I\'m trying to write my own C++ String class for educational and need purposes.
The first thing is that I don\'t know that much about operators and that\'s why I want to
Here's what's going on:
CString a = [CString result of operator +]
, c++ will just call you're copy constructor. Hence the call to CString(CString& )
that you're seeing in the debugger.Now, that's 4 total objects just created, one for each string literal ("hello", and " world"), one for the concatenation of those (the result of the CString::operator +
call, and one to hold the result (CString a = ...
). Each one of those temporary objects will have it's destructor called.
As for why you're not getting the printf, I have no idea. I just copy pasted your code in this file:
#include
#include
[your code]
int main(int argc,char* argv[]) {
CString a = CString("hello") + CString(" world");
printf(a);
}
And when I ran the resulting executable, I got hello world
as the output. This is on Ubuntu with g++ 4.4. Not exactly sure why under the VS debugger it's not printing anything.