/*定义一个point类,有数据成员x和y,重载++和--,同时重载前缀和后缀*/
#include<iostream>
using namespace std;
class Point {
private:
int x,y;
public:
Point(){x=y=0;}
Point& operator ++();
Point operator ++(int);
Point& operator --();
Point operator --(int);
void print(){
cout<<"point:"<<x<<","<<y<<endl;
}
};
Point& Point::operator ++(){
x++;
y++;
return *this;
}
Point Point::operator ++(int){
Point temp=*this;
++*this;
return temp;
}
Point& Point::operator --(){
x--;
y--;
return *this;
}
Point Point::operator --(int){
Point temp=*this;
--*this;
return temp;
}
void main(){
Point obj;
obj.print();
obj++;
obj.print();
++obj;
obj.print();
obj--;
obj.print();
--obj;
obj.print();
}