4-8.txt

来自「思路很清晰的c++课件。例子很简明」· 文本 代码 · 共 36 行

TXT
36
字号
例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 + =
减小字号Ctrl + -
显示快捷键?