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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#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;

}