This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Problem with templates used in a class member.


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]