📄 lab8_1.cpp
字号:
#include <iostream.h>
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 + -