【发布时间】:2014-04-03 08:09:52
【问题描述】:
在这个函数中,我在向量缓存中搜索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));
在编译时,我得到了很多错误。前几行是:
在 /usr/include/c++/4.6/algorithm:63:0 包含的文件中, 来自 my_class.hpp:5, 来自 main.cpp:5: /usr/include/c++/4.6/bits/stl_algo.h: 在函数'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: 从 '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator*, std::vector > >, _Tp = MyCode::MyClass::comp]' my_class.hpp:76:53: 从这里实例化 /usr/include/c++/4.6/bits/stl_algo.h:162:4: 错误:'_first.中的'operator=='不匹配。_gnu_cxx::__normal_iterator<_iterator _container> ::operator* with _Iterator = std::pair*, _Container = std::vector >, __gnu_cxx::__normal_iterator<_iterator _container>::reference = std::pair& == __val'
我该如何解决这个错误?
【问题讨论】:
-
很遗憾,您错过了实际上是错误的错误部分,而不是有关错误的一些额外信息。
-
它仍然不存在。这可能是下一行。
标签: c++ vector compilation iteration std