exam2.cpp

来自「C++语言程序设计题典」· C++ 代码 · 共 19 行

CPP
19
字号
#include <iostream.h>
class Sample
{
	int x,y;
public:
	Sample(int i,int j) { x=i;y=j; }
	friend ostream & operator << (ostream &out,Sample &s);
};
ostream & operator << (ostream &out,Sample &s)
{
	cout << "x=" << s.x << ",y=" << s.y << endl;
	return out;
}
void main()
{
	Sample obj(10,20);
	cout << obj;     //调用重载运算符函数
}

⌨️ 快捷键说明

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