Error C2823: typedef pattern is illegal - function pointer

I want to determine the type of function pointer using patterns. However, VS 2013 me that "the typedef pattern 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 would like this thing to be short. Basically, I need to define a type for a function pointer whose argument has a template class.

+5
source share
1 answer

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

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

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

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

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

+7
source

Source: https://habr.com/ru/post/1204894/


All Articles