Ah! That was it. After switching from Debug to Release mode the output was the same. I am definitely a newbie.
That is masterfully explained, thank you for going into that level of detail. After I read it I looked at theline and I could kick myself for not seeing it.Code:s1 += " world!"
Sorry, no, I don't speak German. At best I might understand snippets of formal French from my high school days, but Google Translate would be my only hope of working with German.
Just out of curiosity, what gave you the impression I understood German? I'm particularly curious what makes me seem smarter than I am.
Great tip, thank you. I didn't even think about the fact g++ was probably not compiling in debug mode.
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.
Good to know. I forget whether it was this book or another that when introducing destructors presented an example of a destructor that only printed output the message that it was called.
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.
Sure, I'm following you there. Now that I realize that g++ was optimizing the code and MSVS was not, I understand why the results were different. Also with Elysia answering my second question, I completely understand what the debug output messages were telling me.
For the most part during my studies I'll be content to treat the compiler output as a black box, provided I understand what the code I'm working with does. It's when I can't read it and understand it that I turn to dissection via debug output to assist.
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.