This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Problem with pointer to shadowed member with namespaces
- To: Phil Blecker <tmwg at inxservices dot com>
- Subject: Re: Problem with pointer to shadowed member with namespaces
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 11 Sep 1998 18:10:52 z
- Cc: egcs at cygnus dot com
- References: <19980910072419.E22612@inxservices.com>
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