以下是我项目的代码段:
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());
以下是Visual Studio 2010的输出错误:
警告1警告C4346:'Event :: eventMap':依赖 name不是类型c:\ users \ admin \ documents \ visual studio 2010 \ projects \ cppsystem \ cppsystem \ main.cpp 67错误2错误C2143: 语法错误:缺少';'之前 'event :: mapper'c:\ users \ admin \ documents \ visual studio 2010 \ projects \ cppsystem \ cppsystem \ main.cpp 67错误3错误C4430: 缺少类型说明符 - 假设为int。注意:C ++不支持 default-int c:\ users \ admin \ documents \ visual studio 2010 \ projects \ cppsystem \ cppsystem \ main.cpp 67错误4错误C1903: 无法从之前的错误中恢复;停止 编译c:\ users \ admin \ documents \ visual studio 2010 \ projects \ cppsystem \ cppsystem \ main.cpp 67
我希望这段代码足够了。 我无法使用该地图的“初始化功能”初始化静态地图成员。 非常感谢!
答案 0 :(得分:5)
您需要typename
告诉编译器eventMap是一种类型。
template<typename Second, typename First = const UINT64>
typename Event<Second, First>::eventMap Event<Second, First>::mapper(Event<Second, First>::StartMapping());