c13_6.cpp

来自「这我们老师对是面向对象程序设计(清华大学出版社)一书制作的PPT」· C++ 代码 · 共 45 行

CPP
45
字号
#include<iostream.h>
class Point
{
	int x,y;
public:
	Point(int x1=0,int y1=0){x=x1,y=y1;}
	Point& operator++()
	{
		x++;y++;
		return *this;
	}
	Point operator++(int)
	{
		Point t=*this;
		x++;y++;
		return t;
	}
    Point& operator--()
	{
		x--;y--;
		return *this;
	}
	Point operator--(int)
	{
		Point t=*this;
		x--;y--;
		return t;
	}
	friend ostream& operator<<(ostream& , Point&);
};
    ostream& operator<<(ostream& os, Point& p)
	{
        os<<"Point("<<p.x<<","<<p.y<<")"<<endl;
		return os;
	}
 void main()
 {
	 Point a(1,2);
	 cout<<a;
	 cout<<a++;
	 cout<<++a;
	 cout<<--a;
	 cout<<a--;
 }
	 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?