I am trying to overload operator + for my class as follows:
MyClass MyClass::operator +(const MyClass& rval) const {
MyClass ret(m_src); // m_src is member of MyClass: char* m_src;
ret.Add(rval); // this->m_src + rval, this method work correctly
return ret; // so, in ret.m_src I have correct value
} // but after this C++ call destructor for ret
Destructor:
delete[] m_src; // because in some methods I allocate dynamic memory
So, destructor clear memory and function return trash. How I can avoid this situation? If I delete destructor, function work normal, but in this case I have memory leak :(
P.S: I can't change prototype of overloading +, unfortunately. Thanks.