在此函數中,我搜索向量緩存中的pair.first。矢量是:對向量中的查找函數中的錯誤
vector<pair<double,unsigned int> > cache;
我已經使用查找功能自定義功能:
struct comp
{
comp(double const& s) : _s(s) { }
bool operator() (pair<double, unsigned int> const& p)
{
return (p.first == _s);
}
double _s;
};
我打電話查找功能:
it = find(cache.begin(),cache.end(),comp(value));
在編譯時,我得到一個很多錯誤。前幾行是:
In file included from /usr/include/c++/4.6/algorithm:63:0, from my_class.hpp:5, from main.cpp:5: /usr/include/c++/4.6/bits/stl_algo.h: In function ‘RandomAccessIterator std::_find(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator*, std::vector > >, _Tp = MyCode::MyClass::comp]’: /usr/include/c++/4.6/bits/stl_algo.h:4326:45: instantiated from ‘_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator*, std::vector > >, _Tp = MyCode::MyClass::comp]’ my_class.hpp:76:53: instantiated from here /usr/include/c++/4.6/bits/stl_algo.h:162:4: error: no match for ‘operator==’ in ‘_first._gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* with _Iterator = std::pair*, _Container = std::vector >, __gnu_cxx::__normal_iterator<_Iterator, _Container>::reference = std::pair& == __val’
我該如何解決這個錯誤?
您不幸錯過了錯誤的部分實際上是錯誤,而不是一些額外的錯誤信息。 –
@Joseph更新。 – Hellboy
它仍然不存在。這可能是下一行。 –