So I have a simple struct used for template definitions.
template<class T>
struct EventListener
{
typedef Functor<T, void, Event*> functor;
typedef void (T::*FunctionPtr)(Event* evt);
};
and in a class I have a function
template<class T>
void addEventListener(const string &eventName, T* target, EventListener<T>::FunctionPtr function);
When I try and build this (VS2010, Windows 7, x64)
I get the following error:
Error C2061: syntax error : identifier 'FunctionPtr'
I feel like this should be valid.
If I replace the T in the function declaration with a specific class…
template<class T>
void addEventListener(const string &eventName, T* target, EventListener<Foobar>::FunctionPtr function);
…The code compiles.
And if I replace the typedef with the actual type…
template<class T>
void addEventListener(const string &eventName, T* target, void(T::*function)(Event* evt));
…it also compiles.
So what am I missing here? I am pretty sure that the latter example will suit my purposes, but I would rather keep it in a typedef.
You have to add the
typenamekeyword:otherwise the C++ parser is mandated by the standard to interpret
FunctionPtras a static method, enum, or data-member, etc. in theEventListenernamespace, not atypedef.