Skip to main content
gamedev.net
🔒 Locked

Pointer to a template member function?

Started by M2 2 replies 850+ views
Original Post
M2
M2
How can I create a pointer to a template member function? Here is some code to perhaps make myself clearer:

struct S{
	template<typename T> void foo(T t){};

	//I think this is the root of all my problems
	template<typename T> void (S::*fooPtr)(T); 

	S(){
		fooPtr = &S::foo;
	}
}; 

Regrettably this code doesn't work, but I hope someone can help me correct my mistake. Or is this simply not possible in c++?
SiCrane
SiCrane
What you seem to want to do isn't allowed. You can create member function pointers to individual instantiations of template functions (like S::foo), but you can't create a pointer to the template itself.
kuphryn
kuphryn
Interesting.

One solution is a class template that returns a pointer to a class.

Kuphryn

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.