Problem with templates used in a class member.

Ram'on Garc'ia ramon@jl1.quim.ucm.es
Wed Sep 9 22:55:00 GMT 1998


This is strange. I think that I sent a response to the list where I
acknowledged that it was my fault to use the function name for a pointer
to member. Anyway, as some replied the construct:

template <class P, void (P::*member)()>
 class x { };

 class user {
 public:
        user() {}
 	void fn() {}
 	x<user, &user::fn> a;
 };

is legal in C+ and is not supported by EGCS.


> That isn't a pointer to function.  And no, you can't leave it out.
> You don't know C++ well enough to help people, this just confuses
> people, please refrain from confusing people.

Could you be more modest, please? Because C++ was a evolving language
until the final approval of the standard, many people are not familiarized
with some details of the syntax. You should be happy if you know so much
C++, but please understand that not everyone is so lucky.

Also note that my comment is only slightly misleading: my major point is
that EGCS does not allow you to use a member function in a template, even
if you use the correct syntax. I acknowledge that I made a mistake: I
should use &user::fn instead of fn, but the rest of my comment still
holds.

The real problem is that EGCS thinks that user is an incomplete class
until it declaration is complete, or inside the body of member functions.
This is correct, with the exception that &user::fn is a valid reference to
a pointer to member inside a template, like in my example.

On the other hand, I apologize to EGCS/C++ developers if my comment
regarding EDG as a better frontend is understimating the quality of their
work. I believe that it is a rather extended opinion that the C++ frontend
of the Edison group is one of the best frontends available. For example,
P. J. Plauger (author of the C++ library included with MS Visual C++) said
he always uses EDG based compilers for demostrating his C++ standard
library, because only these complilers can use his library with all C++
features enabled (that is, no #define to workaround problems). 

I have read the source code of the C++ frontend of EGCS. I found the
problem, but I think that is very difficult to solve. An approach could be
to delay the instatation of the template until the declaration of the
class is complete, probably placing some hooks in the class node.

Any advise?

Ramon





More information about the Gcc mailing list