重载++运算符

来源:互联网 发布:ie内核浏览器for mac 编辑:程序博客网 时间:2024/04/19 14:28
class UPInt
{
public:
    UPInt();
    UPInt(
int);
    UPInt
& operator++();
    
const UPInt operator++(int);
    
/*UPInt& operator--();
    const UPInt operator--(int);
    UPInt& operator+=();
    const UPInt operator+=(int);
*/

private:
    
int pInt;
}
;

UPInt::UPInt()
{
    pInt
=0;
}

UPInt::UPInt(
int t)
{
    pInt
=t;
}

UPInt
& UPInt::operator ++()
{
    
*this += 1;
    
return *this;
}


// const to prevent i++++
const UPInt UPInt::operator ++(int)
{
    UPInt
 Oldptr == this;
    
++(*this);
    
return *Oldptr;
}