This thread is related to this thread: Memory leak in Soln8_05.cpp from Ivor Horton's Beginning Visual C++ 2008 book?.
I basically stuck debug output statements all through a modified copy of the author's solution for one of the chapter exercises in an effort to dissect what constructors, destructors and overloaded functions were being used.
I compiled Soln8_05.cpp (r11) and got two different results that I did not expect.
- CSimpleString(const char* p) was called and I could not find where
- I saw that Microsoft Visual Studio 2010 called a copy constructor when I wasn't expecting it
So, I fired up another VM where I have Ubuntu 10.04 installed and used g++ to compile the code.
I saved the output from both and this is what I have (first two lines in both files were added manually, as was the first line in the diff file):
So, that brings me to my questions:
- Why do G++ and MSVS handle
differently?Code:s1 += " world!"- Why is
called as part of resolvingCode:CSimpleString(const char* p)?Code:s1 += " world!"
Thanks in advance!