I encountered an interesting situation today in a program where I inadvertantly assigned an unsigned integer to a std::string. The VisualStudio C++ compiler did not give any warnings or errors about it, but I happened to notice the bug when I ran the project and it gave me junk characters for my string.
This is kind of what the code looked like:
std::string my_string("");
unsigned int my_number = 1234;
my_string = my_number;
The following code also compiles fine:
std::string my_string("");
unsigned int my_number = 1234;
my_string.operator=(my_number);
The following results in an error:
unsigned int my_number = 1234;
std::string my_string(my_number);
What is going on? How come the compiler will stop the build with the last code block, but let the first 2 code blocks build?