I debugged the program when I came across the following code, which I mistakenly printed, as shown below:
std::string first("Hello");
std::string second = first + second;
std::string first("Hello");
std::string second = first + something_else;
Obviously, I did not try to do this (I canβt think why anyone would like to do this), but it made me think. This is not like the original should work, and I would suggest that it is undefined. Indeed, this was the cause of my problem.
To make the problem more general, consider the following:
SomeType a;
SomeType b = a + b;
Is the behavior undefined simply because it bis not yet initialized (see this answer )?
If the behavior is undefined, then my real question is: why?
undefined , std::string, undefined ( STL, , POD, )?
?
, ++ 11, .