alias5000
alias5000

Reputation: 93

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.

Upvotes: 8

Views: 2349

Answers (1)

Ben Voigt
Ben Voigt

Reputation: 283793

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>)

Upvotes: 11

Related Questions