#include <iostream>
using namespace std;
class Point
{
int _x, _y;
public:
Point(int x = 0, int y = 0) :_x(x), _y(y) {}
Point& operator++();
Point operator++(int);
Point& operator--();
Point operator--(int);
friend ostream& operator<<(ostream& o, const Point& p);
};
Point& Point::operator++()
{
_x++;
_y++;
return *this;
}
Point Point::operator++(int)
{
Point tmp = * this;
++* this;
return tmp;
}
Point& Point::operator--()
{
_x--;
_y--;
return *this;
}
Point Point::operator--(int)
{
Point tmp = *this;
--* this;
return tmp;
}
ostream& operator<<(ostream& o, const Point& p)
{
cout << "(" << p._x << "," << p._y << ")" << endl;
return o;
}
int main()
{
Point p(1, 2);
cout << p << endl; //输出(1,2)
cout << p++ << endl; //输出(1,2)
cout << ++p << endl; //输出(3,4)
cout << p-- << endl; //输出(3,4)
cout << --p << endl; //输出(1,2)
return 0;
}