我有一对函数,简单地说,检索 bimap 的左/右值并打印一条消息(或者,取决于函数的 bool arg,导致程序中的致命错误):
#ifdef __cplusplus
template<typename Lt, typename Rt>
Rt Q_bimapleft( boost::bimap<Lt, Rt> themap, Lt L, bool throwError = false )
{
try
{
Rt returnVal = themap.left.at(L);
return returnVal;
}
catch( ... )
{
if( throwError )
{
Com_Error(ERR_FATAL, "Q_bimapright failure on lookup of %s\n", boost::lexical_cast<char *, Lt>(L));
}
else
{
Com_Printf(S_COLOR_YELLOW "WARNING: Q_bimapright failure on lookup of %s\n", boost::lexical_cast<char *, Lt>(L));
}
}
return (Rt)-1;
}
template<typename Lt, typename Rt>
Lt Q_bimapright( boost::bimap<Lt, Rt> themap, Rt R, bool throwError = false )
{
try
{
Lt returnVal = themap.right.at(R);
return returnVal;
}
catch( ... )
{
if( throwError )
{
Com_Error(ERR_FATAL, "Q_bimapleft failure on lookup of %s\n", boost::lexical_cast<char *, Rt>(R));
}
else
{
Com_Printf(S_COLOR_YELLOW "WARNING: Q_bimapleft failure on lookup of %s\n", boost::lexical_cast<char *, Rt>(R));
}
}
return (Lt)-1;
}
#endif
但是,当我去使用该功能时:
....
boost::bimap<int, std::string> animTable;
char token[1024];
....
int index = Q_bimapleft<int, std::string>(animTable, token);
Intellisense/编译器报告:
IntelliSense: no instance of function template "Q_bimapleft" matches the argument list