我正在尝试创建一个模板函数,它将遍历地图的指定键/值对并检查函数参数中是否存在指定的任何键。
实现如下所示:
代码
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
我以前遇到过这些,但这些通常是由于我犯的容易发现的错误造成的。这里会发生什么?