ok i have a class name CSoulSeeker. i overloaded the addition
operator with this function header CSoulSeeker operator+(const CSoulSeeker& aSoul); the return statement says this return CSoulSeeker(this->m_HitPoints + aSoul.m_HitPoints);
from what i read this is returning a local object...doesnt the local object cease to exist (object is destroyed) onces it reaches end of scope...here is the code if you want to look at it..(this is just an example i am working on to understand more about classes....)
thanks for the helpCode:#include <iostream> #include <cstring> using namespace std; class CSoulSeeker { private: int m_HitPoints; public: // Constructors CSoulSeeker(); CSoulSeeker(int x); CSoulSeeker(CSoulSeeker& aSoul); // Destructor ~CSoulSeeker(); // overloaded assignment operator CSoulSeeker& operator=(const CSoulSeeker& aSoul); // overloaded addition operator CSoulSeeker operator+(const CSoulSeeker& aSoul); // overloaded greater than operator }; CSoulSeeker::CSoulSeeker() { m_HitPoints = 1000; } CSoulSeeker::CSoulSeeker(int x) { m_HitPoints = x; } CSoulSeeker::CSoulSeeker(CSoulSeeker& aSoul) { this->m_HitPoints = aSoul.m_HitPoints; } CSoulSeeker::~CSoulSeeker() { } CSoulSeeker& CSoulSeeker::operator=(const CSoulSeeker& aSoul) { this->m_HitPoints = aSoul.m_HitPoints; return *this; } CSoulSeeker CSoulSeeker::operator+(const CSoulSeeker& aSoul) { return CSoulSeeker(this->m_HitPoints + aSoul.m_HitPoints); } int main() { return 0; }