inline size_t CString_hash_value( const CString& str) /*const*/

   size_t value = _HASH_SEED; 
   size_t size  = str.GetLength(); 
   if (size > 0) { 
  size_t temp = (size / 16) + 1; 
  size -= temp; 
  for (size_t idx = 0; idx <= size; idx += temp) { 
    value += (size_t)str[(int)idx]; 
  } 
   } 
   return(value); 
}

class CString_hash_compare : public hash_compare<CString> 

public:


 size_t operator()(const CString& _Key) const 
 { 
  return((size_t)CString_hash_value(_Key));
 }

 bool operator()(const CString& _Keyval1, const CString& _Keyval2) const 
 { 
  return (comp(_Keyval1, _Keyval2)); 
 } 
};

class CUsers

{

static hash_map<CString, CUser *, CString_hash_compare> UserMap m_users;

}

调用失败!!!

错误 1 error LNK2001: 无法解析的外部符号 "public: static class stdext::hash_map<class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > >,class CUser *,class CString_hash_compare,class std::allocator<struct std::pair<class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const ,class CUser *> > > CUsers::m_users" (?m_users@CUsers@@2V?$hash_map@V?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@PAVCUser@@VCString_hash_compare@@V?$allocator@U?$pair@$$CBV?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@PAVCUser@@@std@@@std@@@stdext@@A) XQBot.obj

解决方案

 

static hash_map<CString, CUser *, CString_hash_compare> UserMap m_users;

改为

hash_map<CString, CUser *, CString_hash_compare> UserMap m_users;

相关文章: