c++(继承 &&菱形继承)
作者:互联网
c++(继承 &&菱形继承)
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
class Animal
{
public:
int m_Age;
};
class Sheep :virtual public Animal
{};
class Tuo :virtual public Animal
{};
class SheepTuo :public Sheep, public Tuo
{};
//菱形继承的解决方案 利用虚继承
void test01()
{
SheepTuo st;
st.Sheep::m_Age = 10;
st.Tuo::m_Age = 20;
cout << st.Sheep::m_Age << endl;
cout << st.Tuo::m_Age << endl;
}
int main()
{
test01();
return 0;
}
标签:Sheep,Animal,继承,c++,public,&&,Tuo,class 来源: https://www.cnblogs.com/lodger47/p/14697413.html