Problem with templates used in a class member.

Carlo Wood carlo@runaway.xs4all.nl
Fri Sep 4 05:03:00 GMT 1998


| template <class P, void (P::*member)()>
| class x { };
| 
| class user {
| public:
|         user() {}
|         void fn() {}
|         x<user, fn> a;
| };

(You forgot a '&' in front of fn)
I *think* that this is not a limitation of egcs...
Consider:

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

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

Which gives the error:

foo.cc:8: incomplete type `user' does not have member `fn'

Its a fact that `user' is incomplete at that point.

You can do:

class user {
public:
        user() {}
	void fn() {}
};

class user_derived : public user {
public:
	x<user, &user::fn> a;
};

which compiles fine.

-- 
 Carlo Wood  <carlo@runaway.xs4all.nl>



More information about the Gcc mailing list