65,213
社区成员
发帖
与我相关
我的任务
分享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;#include "A.h"
A::hash_map_string_factory A::m_factory={A::hash_map_string_factory()};
调用Func还是异常
iterator lower_bound(const key_type& _Keyval)
{ // find leftmost not less than _Keyval in mutable hash table
size_type _Bucket = _Hashval(_Keyval);
for (_Unchecked_iterator _Where = _Begin(_Bucket);//_Begin内出错,vector subscript out of range
_Where != _End(_Bucket); ++_Where)
if (!((_Traits&)*this)(this->_Kfn(*_Where), _Keyval))
return (((_Traits&)*this)(_Keyval,
this->_Kfn(*_Where)) ? end() : _Make_iter(_Where));
return (end());
}
// debug进去看看,是不是m_factory[i]不存在?
public:
typedef std::map<int ,char> Map;
static Map m_Map;
.cpp
CMyThreadPool::Map CMyThreadPool::m_Map;
都没有任何问题