Consider this code:
struct A
{
virtual void foo() {};
};
struct B : private A {};
struct C : private A {};
struct D : A, B, C {};
int main()
{
D d;
d.foo(); // Error: ambiguous access of foo (is it A::foo(), B::foo() or C::foo() ?)
}
The compiler is considering d.foo()
an ambiguous call although both d.B::foo()
and d.C::foo()
are inaccessible and hidden to the user. The only valid call should be d.A::foo()
, why is it ambiguous for the compiler?