std :: find'错误没有匹配函数'

chi*_*iva 29 c++

假设我有一个类A和一个看起来像这样的B类:

Class A
{
private:
    int a;
public :
bool operator==(const A &) const;
//other methods(...)
}

Class B
{
private:
std::vector<A> v;
public:
std::vector<A> &get_v() {return v;};
const std::vector<A>& get_v() const;
}
Run Code Online (Sandbox Code Playgroud)

现在,当我这样做时:

B b;
std::vector<A>::iterator it;
it=std::find (b.get_v().begin(), b.get_v().end(), an item of class A);
Run Code Online (Sandbox Code Playgroud)

我得到的错误是

error: no matching function for call to 'find(std::vector<A>::iterator, std::vector<A>::iterator, A&)
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?谢谢

Ker*_* SB 80

你忘了#include <algorithm>.

  • 好的,神秘的C++错误消息.而不是说,找不到std :: find(因为缺少include),它说模板参数推断/替换失败了. (11认同)
  • @Nuclear重点是可以找到**一个**`std :: find()`,但它是一个带有不同标题的重载的重载,它不是OP正在寻找的标题.在这种情况下抱怨C++是完全正确的,传递的参数不能解析任何声明的重载.如果原因是_"std :: find无法找到"_,那么错误将是_"std :: find未在此范围内声明"_或类似. (3认同)

Vla*_*cow 7

我想你忘了包括标题 <algorithm>