一道二级的题目
#include<iostream>using namespace std;
class Base
{
public:
Base(){x=0;}
int x;
};
class Derived1:virtual public Base
{
public:
Derived1(){x=10;}
};
class Derived2:virtual public Base
{
public:
Derived2(){x=20;}
};
class Derived:public Derived1,protected Derived2
{};
int main()
{
Derived obj;
cout<<obj.x<<endl;
return 0;
}
输出结果是20,我想知道原因,请大大们给我解释。