Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error C2823: a typedef template is illegal - function pointer

I want to define a function pointer type using templates. However, VS 2013 me that 'a typedef template is illegal'. I am trying to write something like this:

template<typename SD>
typedef void(*FuncPtr)(void *object, SD *data);

Unfortunately this does not compile. I'd like to keep this thing short. Basically I need to define a type for a function pointer, whose argument is of a template class.

like image 320
alias5000 Avatar asked Oct 17 '14 04:10

alias5000


1 Answers

Since C++11, you can use the using keyword for an effect very much like typedef, and it allows templates:

template<typename SD>
using FuncPtr = void (*)(void*, SD*);

Before that, you had to separate the template from the typedef:

template<typename SD>
struct FuncPtr
{
     typedef void (*type)(void*, SD*);
};

(and the type name is FuncPtr<U>::type instead of just FuncPtr<U>)

like image 128
Ben Voigt Avatar answered Oct 12 '22 15:10

Ben Voigt