环境:win10,vs2010
报错代码如下:
template <class T>
T * CreateSSObject(T * type, const char * classname, rapidxml::xml_node<char > * pnode)
{
if(strstr(classname, "Open") != NULL) {
char szBuffer[256] = {0};
strcpy(szBuffer, classname);
}
int nType = globalexe.g_classnammap[classname];
// ...
}
报错信息:
1>d:\build\xxx\include\A_SSTypeBase.h(8048): error C2679: 二进制“[”: 没有找到接受“const char *”类型的右操作数的运算符(或没有可接受的转换)
1> c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\hash_map(181): 可能是“int &stdext::hash_map<_Kty,_Ty,_Tr>::operator [](char *&&)”
1> with
1> [
1> _Kty=char *,
1> _Ty=int,
1> _Tr=stdext::hash_compare<const char *,SSOFD_DT::CharLess>
1> ]
1> c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\hash_map(202): 或 “int &stdext::hash_map<_Kty,_Ty,_Tr>::operator [](char *const &)”
1> with
1> [
1> _Kty=char *,
1> _Ty=int,
1> _Tr=stdext::hash_compare<const char *,SSOFD_DT::CharLess>
1> ]
1> 尝试匹配参数列表“(SSOFD_DT::ClassNameMap, const char *)”时
报错原因:classname是const char *类型,而hash_map的[]有[](char *&&)或[](char *const &)两个重载函数,但两个都不匹配
解决方法:将const char *强转为char *,即
int nType = globalexe.g_classnammap[(char *)classname];