⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lab8_1.cpp

📁 清华大学C++参考程序
💻 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;
}

int 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 + -