正如"The C++ Programming Language 3.Edition - Bjarne Stroustrup"中所写.我们可以使用范围解决方案来防止歧义错误.下面的基本程序,当我在类混合使用3层范围时发生错误.但是,当我使用2层没有问题.怎么了?还是像设计问题?错误是;
deneme.cpp: In constructor ‘mix::mix(std::__cxx11::string, int)’:
deneme.cpp:45:22: error: ‘plane’ is an ambiguous base of ‘mix’
pervaneli::plane::engine=b;
Run Code Online (Sandbox Code Playgroud)
我不想制作钻石模型.我很满意两个基础(平面)课程.我只是想了解为什么当我使用3层范围时它会出错.谢谢.
注意:版本是g ++(Ubuntu 5.4.0-6ubuntu1~16.04.4)5.4.0 20160609
#include<iostream>
#include<string>
using namespace std;
class plane{
protected:
int speed;
string name;
public:
int engine;
void its_name(){
cout<<name<<endl;
}
plane(int a=10000){
engine=a;
}
};
class pervaneli:public plane{
public:
pervaneli(string a="-"){
name=a;
}
void belirle(int x){
speed=x;
}
};
class jet:public plane{
public:
jet(string a="-"){
name=a;
}
void belirle(int x){
speed=x;
}
}; …Run Code Online (Sandbox Code Playgroud) c++ ×1