4.6.8菱形继承
#include <iostream>
using namespace std;
class anmial{};
class sheep :virtual public anmial
{
public :
int m_age ;
};
class tuo :public anmial
{
public:
int m_age ;
};
class sheeptuo :public tuo, public sheep
{
};
void test01()
{
sheeptuo st;
st.sheep::m_age = 18;
st.tuo::m_age = 18;
cout << st.sheep::m_age << endl;;
}
int main4_6_8()
{
test01();
system("pause");
return 0;
}
4.6.7多继承语法
#include <iostream>
using namespace std;
class Base1
{
public:
Base1()
{
m_a = 100;
}
int m_a;
};
class Base2
{
public:
Base2()
{
m_a = 200;
}
int m_a;
};
class Son:public Base1,public Base2
{
public:
Son()
{
m_c = 300;
m_d = 400;
}
int m_c;
int m_d;
};
void test01()
{
Son s1;
cout << sizeof(s1) << endl;
cout << s1.Base2::m_a << endl;
}
int main4_6_7()
{
test01();
system("pause");
return 0;
}