Problem with pointer to shadowed member with namespaces
Alexandre Oliva
oliva@dcc.unicamp.br
Fri Sep 11 20:33:00 GMT 1998
Phil Blecker <tmwg@inxservices.com> writes:
> struct OID { int i; }; void g(OID *o);
> namespace n1 { struct N1 { OID o; }; }
> namespace n2 { struct N2 : n1::N1 { OID o; void f(); }; }
> using namespace n2;
> void N2::f() { g(&N1::o); }
> How does one properly refer to the o in n1::N1 in a member of n2::N2?
Enclosing N1::o between parentheses should have worked, because, in
pointer-to-member expressions, there must not be parentheses enclosing
the qualified name. Unfortunately, it does not work, and g++ creates
a pointer to member anyway...
Here are two working alternatives I can think of:
N1 *this1 = this; g(&this1->o);
g(&this->N1::o);
The problem seems to be in qualified name lookup, because:
OID& o_ref = N1::o;
prints:
test.cc: In method `void ::n2::N2::f()':
test.cc:26: warning: initializing non-const `OID &' with `OID ::n1::N1::*' will use a temporary
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
More information about the Gcc
mailing list