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?
修改对象本身,然后返回*this
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.