class UPInt
{
public:
UPInt& operator++(); //前缀
const UPInt& operator++(int); //后缀
UPInt& operator--();
const UPInt& operator--(int);
UPInt& operator+=(int);
...
};
UPInt i;
++i; //调用i.operator++();
i++; //调用i.operator++(0);
--i; //调用i.operator--();
i--; //调用i.operator--(0);
//前缀形式:增加然后取回值
UPInt& UPInt::operator++()
{
*this+=1;
return *this;
}
const UPInt UPInt::operator++(int)
{
UPInt oldValue=*this;
++(*this);
return oldValue;
}