Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Function Pointer as Default Template Argument

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?

like image 343
uray Avatar asked Dec 15 '10 12:12

uray


2 Answers

  1. Yes
  2. No, you don't need PF.

    template<typename R,
             typename A,
             typename F=R (*)(A)> 
    
like image 103
kennytm Avatar answered Oct 10 '22 08:10

kennytm


  1. Yes, it is possible
  2. 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.

like image 42
icecrime Avatar answered Oct 10 '22 06:10

icecrime