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

📄 prog7.cpp

📁 C++语言程序设计题典
💻 CPP
字号:
#include <iostream.h>
class Sample
{
	int n;
public:
	Sample() {}
	Sample(int i) { n=i; }
	void add(Sample &s)      //对象引用作为参数
	{
		if (&s==this)    //不能自已相加,this是当前对象的指针
			cout << "自已不能相加" << endl;
		else
			n+=s.n;
	}
	void disp()	{ cout << endl << "  n=" << n << endl; }
};
void main()
{
	Sample s1(10),s2(20),s3(30),s4(40);
	s1.add(s2);
	s1.add(s3);
	s1.add(s4);
	s1.disp();
	cout << endl;
}

⌨️ 快捷键说明

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