c++11中unordered_map作为类的静态成员,怎么初始化?
c++11中unordered_map作为类的静态成员,怎么初始化?
假如头文件A.h如下:
struct eq {
bool operator()(const TCHAR *s1, const TCHAR *s2) const {
return _tccmp(s1, s2) == 0;
}
bool operator()(uint a1, uint a2) const {
return a1 == a2;
}
bool operator()(int s1, int s2) const {
return s1 == s2;
}
bool operator()(const tstring &s1, const tstring &s2) const {
return s1 == s2;
}
};
class A
{
private:
typedef unordered_map<const TCHAR *, A*, hash<const TCHAR *>, eq> hash_map_string_factory;
static hash_map_string_factory m_factory;
//...其它方法和构造函数略
static void Func(const TCHAR * i, A * factory)
{
m_factory[i]=factory;//这里报异常了。。。。
}
};
#include "A.h"
A::hash_map_string_factory A::m_factory;