Here is a code snippet from my project:
template<typename Second, typename First = const UINT64>
class Event : virtual public id_manager<>
{
friend class EventHandler;
typedef std::map<First, EventHandler> eventMap;
static eventMap mapper;
static eventMap StartMapping()
{
eventMap temp;
return temp;
}
public:
Event(){}
void operator+=(EventHandler _handler)
{
mapper[this->getID()] = _handler;
}
};
// INITIALIZATION FAILED HERE:
template<typename Second, typename First = const UINT64>
Event<Second, First>::eventMap Event<Second, First>::mapper(Event<Second, First>::StartMapping());
Here is output error from Visual studio 2010:
Warning 1 warning C4346: ‘Event::eventMap’ : dependent
name is not a type c:\users\admin\documents\visual studio
2010\projects\cppsystem\cppsystem\main.cpp 67 Error 2 error C2143:
syntax error : missing ‘;’ before
‘Event::mapper’ c:\users\admin\documents\visual studio
2010\projects\cppsystem\cppsystem\main.cpp 67 Error 3 error C4430:
missing type specifier – int assumed. Note: C++ does not support
default-int c:\users\admin\documents\visual studio
2010\projects\cppsystem\cppsystem\main.cpp 67 Error 4 error C1903:
unable to recover from previous error(s); stopping
compilation c:\users\admin\documents\visual studio
2010\projects\cppsystem\cppsystem\main.cpp 67
I hope this pice of code is enough.
I can’t initialize static map member using “initialization functin” for that map.
thanks alot!
You need
typenameto tell the compiler that the eventMap is a type.See The “typename” keyword