Implicit conversion loses integer precision

I’m receiving this error: Implicit conversion loses integer precision: ‘size_type’ (aka ‘unsigned long’) to ‘int32’ (aka ‘int’)

It’s not preventing me from running the code, but I would like to know what it’s about. Thanks!

1 Like

std::string::length() returns std::size_t which is unsigned integer (i.e. non-negative value), while int32 is signed and they both represent different ranges of integers hence the compiler warning. In your case there won’t be any ill-effects because if this warning, so either you can just ignore it, or you can shut up the compiler by an explicit conversion (int32 HiddenWordLength = (int32) MyHiddenWord.length();), or you can fix it by declaring all integers as std::size_t (including the ones in the two for loops) in your SubmitGuess method.

4 Likes

Got a similar problem/warning.

Hope this reply isn’t too late.

1 Like

Privacy & Terms