是否可以从程序中其他位置的派生类实例访问基类公共成员。
class base {
public:
int x;
base(int xx){
x = xx;
}
};
class derived : base {
public:
derived(int xx) : base(xx){
}
};
class main {
public:
derived * myDerived;
void m1(){
myDerived = new derived(5);
m2(myDerived);
}
void m2(derived * myDerived){
printf("%i", myDerived->x);
}
};
在上面的代码之后,我得到了以下错误。
`error: 'int base::x' is inaccessible`