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)
Davide Spataro
  • 7,319
  • 1
  • 24
  • 36
Kirti Kedia
  • 133
  • 6

3 Answers3

10

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

template<class T>
using computeSizeFunc = int (*)(T data);
r3mus n0x
  • 5,954
  • 1
  • 13
  • 34
2

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

template<class T>
using computeSizeFunc = int (T data);
Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
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);
};
Thomas Lang
  • 770
  • 1
  • 7
  • 17