?? lab8_1.cpp
字號:
#include <iostream>
using namespace std;
class Point
{
private:
int _x, _y;
public:
Point& operator++();
Point operator++(int);
Point& operator--();
Point operator--(int);
Point() { _x = _y = 0; }
int x() { return _x; }
int y() { return _y; }
};
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 A;
cout << "A的值為:" << A.x() << " , " << A.y() << endl;
A++;
cout << "A的值為:" << A.x() << " , " << A.y() << endl;
++A;
cout << "A的值為:" << A.x() << " , " << A.y() << endl;
A--;
cout << "A的值為:" << A.x() << " , " << A.y() << endl;
--A;
cout << "A的值為:" << A.x() << " , " << A.y() << endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -