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

📄 4-8.txt

📁 思路很清晰的c++课件。例子很简明
💻 TXT
字号:
例4.8 派生类构造函数和析构函数的构造规则

#include <iostream.h>

class base{
	int i;
public:
	base(int n)
	{ cout<<"Constructing base class\n";
	  i=n;
	}
	~base()
	{ cout<<"Destruction base class\n";}
	void showi()
	{ cout<<i<<endl;}
};

class derive:public base{
	int j;
public:
	derive(int n,int m):base(m)
	{ cout<<"Constructing derived class\n";
	  j=n;
	}
	~derive()
	{ cout<<"Destructing derived class\n";}
	void showj()
	{ cout<<j<<endl;}
};

void main()
{	derive obj(30,40);
	obj.showi();
	obj.showj();
}

⌨️ 快捷键说明

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