单目运算符重载为成员函数


#include<iostream>
using namespace std;
class point
{
private:
    int x,y;
public:
    point(int xx=0,int yy=0)
    {x=xx;y=yy;}
    point operator ++(int)//后置++加上一个int  前置不用加
    {
        x++;
        y++;
        return *this;
    }
void display()
{cout<<"x="<<x<<",y="<<y<<endl;}
};

int main()
{    
    point a(1,2);
    a++;
    a.display();
    return 0;

}

猜你喜欢

转载自blog.csdn.net/laizhuocheng/article/details/81167991
今日推荐