l7_8.cpp

来自「《C++程序设计教程》电子教案及例题源码」· C++ 代码 · 共 53 行

CPP
53
字号
#include <iostream.h>
class CBase1 
{
protected:
	int b;
public:
	CBase1(int x=0)
	{
		b=x;
	}
	int GetB()
	{
		return b;
	}
};

class CBase2 
{
private:
	int b;
public:
	CBase2(int x=0)
	{
		b=x;
	}
	int GetB()
	{
		return b;
	}
};

class CDerived : public CBase1,private CBase2 
{
protected:
	int d;
public:
	CDerived(int x,int y, int z):CBase1(x),CBase2(y)
	{
		d=z;
	}
	void Output()
	{
		cout << d << b << endl;  // CDerived::b' is ambiguous
	}
};

void main()
{
	CDerived d1(1,2,3);
	int x = d1.GetB();  //CDerived::GetB' is ambiguous
	d1.Output();
}

⌨️ 快捷键说明

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