我将尝试创建一个模板函数,该函数将迭代地遍历映射(map)中指定的键值对,并检查是否存在函数参数中指定的任何键。
实现如下所示:
代码
实现如下所示:
代码
template < class Key, class Value >
bool CheckMapForExistingEntry( const std::map< Key, Value >& map, const std::string& key )
{
std::map< Key, Value >::iterator it = map.lower_bound( key );
bool keyExists = ( it != map.end && !( map.key_comp() ( key, it->first ) ) );
if ( keyExists )
{
return true;
}
return false;
}
然而,出于某种原因,我似乎无法弄清楚为什么我的代码无法编译。相反,我收到了以下错误:
error: expected ';' before 'it'
error: 'it' was not declared in this scope
我以前遇到过这些问题,但通常是由于我自己犯的易于发现的错误。这里可能出了什么问题?