c++ 多重继承的多个父类有包含关系怎么办,比如B是A的成员变量?B和A之间有继承关系呢?
事实证明是没有问题的
详见代码:
#include <iostream>
using namespace std;
class B
{
public:
int bm1;
B():bm1(5) {
}
protected:
private:
};
class A
{
public:
//int bm1;
B ab;
protected:
private:
};
class C : public A , public B
{
public:
protected:
private:
};
int main()
{
C c;
c.ab.bm1 = 6;
cout<<c.ab.bm1<<endl;
cout<<c.bm1<<endl;
return 0;
}
输出:
6
5