Based on my reading, the following code:
string aggregate = "give" + 'n';
Should create a result line with the value:
"given".
Instead, it produces garbage. Why doesn't the following happen?
"give" is converted to std :: string through a constructor that takes a pointer to an array of characters.
An overload of '+' is called, which takes std :: string and a character, returning a new line.
I base my theory on this manual page.
Now I heard that the first argument of the overloaded operator is not a candidate for constructor conversion if the operator is a member of the class. In my opinion, I read this in Koenig and Mu. But in this case, I understand that the + operator is a non-member overload.
I understand that this sounds like a ridiculous over-complication, but I like to know FOR SURE what happens when I write code.
source share