Hello,
I am reading some c++ tutorial about operator overloading, and the following code given as an example for operator+ overloading has had me very much confused.
As I understand it, "MyClass result" only creates the object on stack, so it is only "alive" within the scope of the function, and will be destoried at the end of the function?Code:const MyClass MyClass::operator+(const MyClass &other) const { MyClass result = *this; // Make a copy of myself. Same as MyClass result(*this); result += other; // Use += to add other to the copy. return result; // All done! }



LinkBack URL
About LinkBacks


