0

I want to create a function pointer for the method signature having Template as a parameter

Template<class T>
typedef int (*computeSizeFunc)(T data);

I tried this, and this is the error

 error: template declaration of 'typedef'
 typedef  int (*computeSizeFunc)(T data).

This is the method signature for which I am trying to write Function Pointer

template<class T>
int getSize (T data)
0

3 Answers 3

10

You should use C++11 type-alias declaration instead:

template<class T>
using computeSizeFunc = int (*)(T data);
2

typedef doesn't allow template usage, you you should use using:

template<class T>
using computeSizeFunc = int (T data);
1

As a pre-C++11 alternative to the other methods you can use a workaround like this:

template< class Arg >
struct computeSizeFunc {
  typedef int (*funcImpl)(Arg data);
};

Not the answer you're looking for? Browse other questions tagged or ask your own question.