Why can't a C ++ permission statement access an ambiguous database?

Consider the code below:

#include <iostream> #include <string> using namespace std; // helpers void disp1(string s, int i, void* p) { cout << s << " constructed with " << i << " @ " << p << "\n"; } void disp2(string s, void* p) { cout << s << " @ " << p << "\n"; } // class hierarchy: // // AA // | | // BC // \ / // D // struct A { A() { disp1("A", 0, this); } void tell() { disp2("A", this); } }; struct B : A { B() { disp1("B", 0, this); } void tell() { disp2("B", this); } }; struct C : A { C() { disp1("C", 0, this); } void tell() { disp2("C", this); } }; struct D : B, C { D() { disp1("D", 0, this); } void tell() { disp2("D", this); } }; int main() { D d; static_cast<B*>(&d)->A::tell(); // OK: call B::A::tell() static_cast<C*>(&d)->A::tell(); // OK: call C::A::tell() // dB::A::tell(); // compile error: 'A' is an ambiguous base of 'D' } 

Why do I get a compiler error on a qualified call, for example dB::A::tell(); ? It is true that A is the ambiguous base of D , but why does it matter here?

I directly say "call tell() of A of B ". What is ambiguous here?

+7
c ++ language-lawyer multiple-inheritance
source share

No one has answered this question yet.

See similar questions:

24
call base class method from a derived class object
thirteen
The Diamond of Death and the scale resolution operator (C ++)
3
Overload resolution / ambiguity when searching for a name (which one)

or similar:

8499
What is the "->" operator in C ++?
1783
C ++ 11 introduced a standardized memory model. What does it mean? And how will this affect C ++ programming?
1675
Why is reading strings from stdin much slower in C ++ than Python?
1406
Why does 0.1f to 0 slow down performance by 10x?
1138
Why do we need virtual functions in C ++?
824
Why do C ++ programmers minimize the use of "new"?
7
Why does g ++ complete the initialization of std :: function <> from a type with a conversion operator and inaccessible function call statements?
2
Why is this function overloaded with an error in C ++?
one
Why are these overloaded function calls ambiguous?
0
C ++ operator overloads ambiguity of resolution

All Articles