对Point类进行重载++,--运算符
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
class Point
{
private:
int x,y;
public:
Point(int a=0,int b=0)
{
x=a;
y=b;
}
~Point(){}
Point operator++()
{
Point p;
p.x=x+1;
p.y=y+1;
x=x+1;
y=y+1;
return p;
}
Point operator++(int)
{
Point p;
p.x=x;
p.y=y;
x+=1;
y+=1;
return p;
}
Point& operator--()
{
Point p;
p.x=x-1;
p.y=y-1;
x=x-1;
y=y-1;
return p;
}
Point operator--(int)
{
Point p;
p.x=x;
p.y=y;
x=x-1;
y=y-1;
return p;
}
void shown()
{
cout<<x<<" ,"<<y<<endl;
}
};
int main()
{
Point p0(0,0),p1(2,3),p2(1,4);
p0.shown();
p0=p1++;
p0.shown();
}