my short sightedness........ help....
Just working to learn some C++ and even though this program worked I failed to understand the underlying concept.......
This is snippet from a program ..... and this is an overloaded "+" operator.... CmyString is a class with two members a string m_pstr and an integer length (length of the string)....pretty simple layout....
my first question why is the function parameter "const CmyString& b" and not just "const CmyString b"
I also had a overlaoded "=" operator in the program
CmyString CmyString::operator+(const CmyString& b)
temp.length = this->length + b.length;
delete  temp.m_pstr;
temp.m_pstr = new char [temp.length + 1];
So lets say there are three objects :
CmyString& CmyString::operator=(const CmyString& b)
if(this != &b)
delete  m_pstr;
m_pstr = new char[strlen(b.m_pstr) + 1];
A statement like
c = a+b;
would execute from left to right so would be
but the object returned by a.operator+(b) will be destroyed... or will it not be ..... ????? I think I got confused in the concepts or refrence and pointers somewhere ......