在未加virtual时会出现这种情况
代码中需要指定调用哪个父类的方法,这样就很奇怪
而加了virtual后就不需要了
#include<iostream> using std::cout; using std::endl; class Base { protected: int value; public: Base() { cout << "in Base" << endl; } }; class DerivedA : virtual protected Base { public: DerivedA() { cout << "in DerivedA" << endl; } }; class DerivedB : virtual protected Base { public: DerivedB() { cout << "in DerivedB" << endl; } }; class MyClass : DerivedA, DerivedB { public: MyClass() { cout << "in MyClass" << value << endl; } }; int main() { MyClass myClass; }