下面的代码:C++多重继承私有成员ambigious访问
class A1 {
public:
int x;
};
class A2 {
private:
int x() { return 67; }
};
class M : public A1, public A2 {};
int main() {
M m;
m.x;
}
编译错误:
error C2385: ambiguous access of 'x'
note: could be the 'x' in base 'A1'
note: or could be the 'x' in base 'A2'
但是,为什么?只有A1::x
应可见M. A2::x
应该是纯粹的本地。
在C++中,*名称查找*发生之前*进行成员访问检查*。 – WhiZTiM
您之前提出的问题: http://stackoverflow.com/questions/6397938/ambiguous-access –