Reputation: 133
class LongInt
{
public: LongInt& operator++(); //returning a reference
}
LongInt LongInt::operator++()
{
...
LongInt d;
d.setVector(temp);
return d; //returning a reference to an object that will be wiped out because it is out of scope
}
I am kinda confused here. I apparently have to return by reference to overload the increment operator, but I don't think that's even possible. I get a memory fault, because the object my pointer is pointing to disappears. So how should I overload the ++ operator?
Upvotes: 0
Views: 71