C++ Logo

std-discussion

Advanced search

Name lookup

From: Russell Shaw <rjshaw_at_[hidden]>
Date: Thu, 27 Feb 2025 00:07:24 +1100
Hi,

In [class.member.lookup], using g++, i get "error: request for member ‘x’ is
ambiguous" for 'f.x = 0;'

------------------------------------------------------
example 1

struct A { int x; }; // S(x,A) = { { A::x }, { A } }
struct B { float x; }; // S(x,B) = { { B::x }, { B } }
struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
struct D: public virtual C { }; // S(x,D) = S(x,C)
struct E: public virtual C { char x; }; // S(x,E) = { { E::x }, { E } }
struct F: public D, public E { }; // S(x,F) = S(x,E)

int main() {
   F f;
   f.x = 0; // OK, lookup finds E::x
}
------------------------------------------------------

I agree with g++ because the inheritance diagram is:

A.x B.x
  \ /
   C
  / \
D E.x
  \ /
   F

f.x could be A.x, B.x, or E.x, but the standard is saying that it's unambiguous.

Received on 2025-02-26 13:07:31