我为obj.a::get();
得到的错误是a类无法访问,我知道obj.get()
会标记错误,但我想这应该有效,这里的问题是什么?
class a {
int arg1;
public:
a(int i){
arg1 = i;
cout << "a() called" << endl;
}
void get() {
cout << "arg1=" << arg1 << endl;
}
};
class b {
int arg2;
public:
b(int j) {
arg2 = j;
cout << "b() called" << endl;
}
void get() {
cout << "arg2=" << arg2 << endl;
}
};
class c: private a, private b {
int arg3;
public:
c(int i, int j, int k): b(k), a(j) {
arg3 = k;
cout << "c() called" << endl;
}
};
int main() {
c obj(1, 2, 3);
obj.a::get();
}
答案 0 :(得分:10)
c
使用private
从a
派生,因此a
的{{1}}子对象无法从{{1}的成员函数的函数中访问}}