123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include <iostream>
- using namespace std;
- class Point {
- private:
- int _x, _y;
-
- public:
- Point(int x, int y) : _x(x), _y(y) {}
-
- //前置
- Point& operator++() {
- ++_x;
- ++_y;
- return *this;
- }
-
- //后置
- Point operator++(int) {
- Point temp = *this;
- _x++;
- _y++;
- return temp;
- }
-
- Point& operator--() {
- --_x;
- --_y;
- return *this;
- }
-
- Point operator--(int) {
- Point temp = *this;
- _x--;
- _y--;
- return temp;
- }
-
- friend ostream& operator<<(ostream& os, const Point& p) {
- os << "(" << p._x << ", " << p._y << ")";
- return os;
- }
-
- friend istream& operator>>(istream& is, Point& p) {
- is >>p._x >> p._y;
- return is;
- }
- };
- int main() {
- Point p(1,2);
- cin >> p;
-
- cout << p << endl;
-
- Point p1 = p++;
- cout << p1 << endl;
-
- Point p2 = ++p;
- cout << p2 << endl;
-
- Point p3 = p--;
- cout << p3 << endl;
-
- Point p4 = --p;
- cout << p4 << endl;
-
- return 0;
- }
|