#include<iostream>
using namespace std;
class animal {
public:
int m_age;
};//在继承方式前加virtual变为虚继承,animal叫虚基类
class sheep :virtual public animal {
};
class tuo :virtual public animal {
};
class sheeptuo :public sheep,public tuo {
};
void test() {
sheeptuo s;
s.sheep::m_age = 18;
s.tuo::m_age = 28;
cout << "s.sheep::m_age =" << s.sheep::m_age << endl;
cout << "s.tuo::m_age =" << s.tuo ::m_age << endl;
}
int main() {
test();
return 0;
}
黑马-继承-菱形继承-笔记
最新推荐文章于 2024-09-28 21:20:29 发布