关于多继承的二义性问题
#include <iostream.h>class BaseBase{
int x;
public:
BaseBase(){x=1;}
};
class Base1:public BaseBase{
public:
Base1(){};
};
class Base2:public BaseBase{
public:
Base2(){};
};
class Derived:public Base1,public Base2{
public:
Derived(){x=14;}
};
由于对象中包括两个X值,所以编译程序无法确定这个值是属于哪一个份的,解决方法是在前面加路径标志,如
class Derived:public Base1,public Base2{
public:
Derived(){Base1::x=45;Base2::x=41;}
};
但编译器还是不能通过.会出现如下问题:
F:\lian\lian.cpp(17) : error C2248: 'x' : cannot access private member declared in class 'BaseBase'
F:\lian\lian.cpp(3) : see declaration of 'x'
F:\lian\lian.cpp(17) : error C2248: 'x' : cannot access private member declared in class 'BaseBase'
F:\lian\lian.cpp(3) : see declaration of 'x'
Error executing cl.exe.
lian.obj - 2 error(s), 0 warning(s)
请教各位: