class A { public: int a; };
class B : public virtual A { public: using A::a; };
class C : public virtual A { public: using A::a; };
class D : public C, public B { };
class W { public: int w; };
class X : public virtual W { public: using W::w; };
class Y : public virtual W { };
class Z : public Y, public X { };
int main(){
D d;
d.a = 0; // Error
Z z;
z.w = 0; // Correct
return 0;
}
The first group of class declarations (A
, B
, C
and D
) and the second (W
, X
, Y
and Z
) are built similarly except that class C
has a using declaration (using A::a
) and class Y
doesn't.
When trying to access member a
in d.a = 0
I get an error in Clang (error: member 'a' found in multiple base classes of different types
) and in GCC (error: request for member 'a' is ambiguous
). I checked recent and old versions of both compilers and all of them agree. However, accessing w
in z.w = 0
compiles successfully.
What is the reason of this ambiguity when accessing a
?
To the best of my knowledge, both access declarations in classes B
and C
refer to the same base class member. And by the way, if I remove them the test compiles successfully because a
is already publicly accessible ( public
access specifier ).
Thanks in advance.
Note: The above code is a slightly modified test from SolidSands' SuperTest suite.