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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21609490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:43:53  来源:igfitidea点击:

std::find 'error no matching function'

c++

提问by chiva

Say that I have a class A and a class B that look like that:

假设我有一个 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;
}

Now when I do that:

现在,当我这样做时:

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

The error I get is

我得到的错误是

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

Am I missing something ? Thanks

我错过了什么吗?谢谢

回答by Kerrek SB

You forgot to #include <algorithm>.

你忘了#include <algorithm>

回答by Vlad from Moscow

I think you forgot include header <algorithm>

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

回答by parmod

You forgot include this header file

你忘了包含这个头文件

#include<vector>

.

.