Answer the question
In order to leave comments, you need to log in
Is it possible to pass a function pointer as a template parameter?
Recently I started to deal with templates, and this question immediately arose.
With non-static class methods, everything is clear, it turned out to be easier than I thought:
template<class Obj, void*(Obj::*publicMethod)(void*))>
func(Obj* pObj, void* arg)
{
return pObj->publicMethod(arg);
}
Answer the question
In order to leave comments, you need to log in
Using typedef it is possible.
ideone.com/tzKAng
But don't do that :) In this case, each forwarded function will generate its own code. Secondly, there’s no way to throw std:: function, nothing will most likely work with lambdas either, I’m generally silent about std::bind.
Em.
std::function
std::bind
Lambda functions
Classic function pointers.
Study to enlightenment
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question