This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Problem with templates used in a class member.
- To: "Ram'on Garc'ia" <ramon at jl1 dot quim dot ucm dot es>
- Subject: Re: Problem with templates used in a class member.
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 04 Sep 1998 02:08:46 -0300
- Cc: egcs at cygnus dot com
- References: <Pine.LNX.3.96.980903043003.13483A-100000@jl1.quim.ucm.es>
Ram'on Garc'ia <ramon@jl1.quim.ucm.es> writes:
> For example, the followin correct code does not compile with EGCS 1.1a:
This is not correct code, for that matter:
> template <class P, void (P::*member)()> class x { };
> class user { public: user() {} void fn() {} x<user, fn> a; };
`fn' is not a valid expression; you must write `&user::fn' to get a
pointer to member.
Unfortunately, egcs 1.1 won't compile the `&user::fn' variant either,
but I believe it should. One might argue that class user is not
complete at that point [class.mem/2], but seems not to be necessary to
form a pointer to member [expr.unary.op/3]. Qualified name lookup
[basic.lookup.qual] should succeed [class.qual]/1, because the
potential scope of a member declaration starts at its point of
declaration [basic.scope.class], but it also includes the body and the
default arguments of member functions and constructor initializers.
This explains why you cannot refer to user::fn in a declaration before
fn is declared, but you can call a method from another before the
former is declared.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil