#include <iostream>
using namespace std;
class Point {
public:Point() {}
Point(float x, float y) {
this->x = x;
this->y = y;
}
Point operator++(); Point operator--();
Point operator++(int); Point operator--(int);
friend ostream& operator<<(ostream& out, const Point& p);
~Point() {}
private:
float x;
float y;
};
Point Point::operator++() {
return Point(++x, ++y);
}
Point Point::operator++(int) {
Point p = (*this);
++(*this);
return p;
}
Point Point::operator--() {
return Point(--x, --y);
}
Point Point::operator--(int) {
Point p = (*this);
--(*this);
return p;
}
ostream& operator<<(ostream& out, const Point& p) {
out << "(" << p.x << "," << p.y << ")";
return out;
}
int main()
{
Point p(8, 8);
cout << "p初始坐标:" << p << endl;
p.operator ++();
cout << "++p:" << p << endl;
p.operator++(0);
cout << "p++:" << p << endl;
p.operator --();
cout << "--p:" << p << endl;
p.operator--(0);
cout << "p--:" << p << endl;
return 0;
}