how do I write a function pointer as default template argument, I'am guessing to write it like this:
template<typename R,
typename A,
typename F=R (*PF)(A)>
class FunctionPtr { ...
my question is,
1.is开发者_开发百科 it possible?
2.if it is and my guess code above is correct, what the purpose of PF
here? do I need this?
- Yes
No, you don't need PF.
template<typename R, typename A, typename F=R (*)(A)>
- Yes, it is possible
The
PF
not only is useless but must be removed in this context. It would, for example, be necessary in the context of a function pointer declaration :int (*PF)(double) = &A::foo; // declares a 'PF' variable of type 'int (*)(double)'
but it is neither required nor legal here.
I suggest typedef
ing pointer to function. typedef R (*PF)(A);
then give PF
as a default template argument.
精彩评论