Hi!
While testing a project I noticed a weird behaviour.
Here is the draft class:
Code:
Class MyClass
{
public:
MyClass();
~MyClass();
MyClass self() { return *this; }
}
And here comes the problem:
Code:
MyClass anObj;
anObj.self();
// PROBLEM HERE - after returning from self() function, de destructor of MyClass gets called
// do something
If I change the self() to return a reference:
Code:
MyClass& self() { return *this; }
then the destructor isn't called.
Do you have a good explanation for this one?