【发布时间】:2017-02-12 16:46:37
【问题描述】:
以下代码:
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++ 中,name-lookup 发生在 成员访问检查 之前。
标签: c++ multiple-inheritance access-control private-members name-lookup