我收到奇怪的拼写错误,没有任何意义。我担心这可能是 C++ 编译器问题(在带有 10.6.8 和 Xcode 3.x 的 Mac 上)。如果有人能真正发现这个问题,我将不胜感激:
template<typename T> int getIdxInVector(const std::vector<T>& vec, const T& toMatch)
{
std::vector<T>::const_iterator cit = std::find(vec.begin(),vec.end(),toMatch);
return( cit != vec.end() ? cit - vec.begin() : -1 );
}
以下是我得到的错误:
LooseFunctions.h:27: error: expected `;' before 'cit'
LooseFunctions.h:28: error: 'cit' was not declared in this scope
LooseFunctions.h:27: error: dependent-name 'std::vector<T,std::allocator<_CharT> >::const_iterator' is parsed as a non-type, but instantiation yields a type
LooseFunctions.h:27: note: say 'typename std::vector<T,std::allocator<_CharT> >::const_iterator' if a type is meant
谢谢你的帮助!