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?
No, you don't need PF.
template<typename R, typename A, typename F=R (*)(A)>
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.