demo_4_multiple_inheritance_ambiguity.cpp
来自「对于一个初涉VC++的人来书」· C++ 代码 · 共 38 行
CPP
38 行
//**********************************************
// 多继承的名字冲突问题的二义性错误
//**********************************************
#include<iostream.h>
class Base1 //基类1
{
public:
void show() { cout<<i<<endl; }
protected:
int i;
};
class Base2 //基类2
{
public:
void show() { cout<<j<<endl; }
protected:
int j;
};
class Derived: public Base1,public Base2 //多继承的派生类
{
public:
Derived(int x,int y) { i=x; j=y; }
};
void main()
{
Derived object(10,20); //声明一个派生类的对象
// object.show(); //Error: 'Derived::show' is ambiguous (二义性错误)
//Warning: could be the 'show' in base 'Base1' of class 'Derived'
//Warning: or the 'show' in base 'Base2' of class 'Derived'
return;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?