c++中的菱形继承
class Animal {
public:int m_age;
};
class Sheep:public Animal {};
class Tuo:public Animal{};
class SheepTuo :public Sheep , public Tuo{};
SheepTuo st;
st.m_age = 18;
m_age是谁的无法区分
class Animal {
public:int m_age;
};
class Sheep:virtual public Animal {};
class Tuo:virtual public Animal{};
class SheepTuo :public Sheep , public Tuo{};
SheepTuo st;
//st.m_age = 18;
st.Sheep::m_age = 18;
st.Tuo::m_age = 88;
cout << "st.Sheep::m_age =" << st.Sheep::m_age << endl;
cout << "st.Tuo::m_age =" << st.Tuo::m_age << endl;
cout << "st.m_age =" << st.m_age << endl;
+virtual使其变为虚继承。