次のコード: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 –