l7_7.cpp

来自「《C++程序设计教程》-杨国兴-电子教案及例题 C++程序设计PPT课件 h」· C++ 代码 · 共 56 行

CPP
56
字号
#include <iostream.h>
class CBase1 
{
protected:
	int b;
public:
	CBase1(int x=0)
	{
		b=x;
		cout << "Construct CBase1!  " << b <<endl;
	}
	~CBase1()
	{
		cout << "Destruct CBase1!  " << b <<endl;
	}
};

class CBase2 
{
protected:
	int b;
public:
	CBase2(int x=0)
	{
		b=x;
		cout << "Construct CBase2!  " << b <<endl;
	}
	~CBase2()
	{
		cout << "Destruct CBase2!  " << b <<endl;
	}
};

class CDerived : public CBase1,private CBase2 
{
protected:
	CBase1 b1;
	CBase2 b2;
	int d;
public:
	CDerived(int x,int y, int z):b1(y),CBase2(y),b2(z),CBase1(x)
	{
		d=z;
		cout << "Construct CDerived!  " << d <<endl;
	}
	~CDerived()
	{
		cout << "Destruct CDerived!  " << d <<endl;
	}
};

void main()
{
	CDerived d1(1,2,3);
}

⌨️ 快捷键说明

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