line and I could kick myself for not seeing it.Code:
s1 += " world!"
Just out of curiosity, what gave you the impression I understood German? I'm particularly curious what makes me seem smarter than I am. ;)
I probably didn't mention it, but what I did was read the exercise directions, solved it myself and then compared my solution against the author's solution.
My code was ugly.
It worked, but each overloaded operator+ function was a copy/paste/modify of each other which resulted in a bunch of duplicated code. As I was comparing my code against the author's I found what looked like a memory leak in both my code and the author's. After getting feedback (see thread I mention my first post to this thread) from oogabooga, I went and modified the author's code to include the proposed fix.
I've was trying to work with the author's code as-is without making modifications to how it worked. This was because I didn't fully understand what I was dealing with yet and I felt that making enhancements that weren't fully obvious (to me) would confuse me further.
I've spent many years trying to learn C++ (off/on) and all previous times I got hung up on trying different ways to do something instead of just going through the material. I've got one book I'm going through and about 5-6 other resources (mainly other books) I refer to when I run up against something I feel I need to know more about. The concept of pointers is a good example. I used close to all of my resources and still ended up referring to web sites for clarification.
I'm using that same approach here so I can see what order the various constructors/functions fire to follow the code flow.
Thankfully I've been using debug mode all along with MSVS, so it has been both useful and accurate (from what I could tell). I just so happened to test with g++ this time and ran into the discrepancy. Thanks to everyone for making clear why.
I've read of too many cases where the compiler takes the liberty to optimize away user created loops and slower code when it's able to. My exposure to Gentoo years ago when I had to set compilation flags for package builds helped to impress this upon me. Thanks for the warning though, as it's important not to lose focus of the goal. :)