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.
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>
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With