51

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

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

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
chiva
  • 535
  • 1
  • 4
  • 7

3 Answers3

129

You forgot to #include <algorithm>.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • Yes I figured it out! Thanks – chiva Feb 06 '14 at 17:21
  • 16
    Nice, cryptic C++ error messages. Instead of saying, that std::find cannot be found (because of missing include), it says template argument deduction/substitution failed. – Nuclear May 13 '15 at 11:03
  • 3
    @Nuclear The point is that **an** `std::find()` can be found, but it's an overload with a different signature from a different header, which is not the one the OP was looking for. C++ is perfectly correct to complain in this case that the passed arguments do not enable resolution to any declared overload. If the cause were that _"std::find cannot be found"_, then the error would be _"std::find was not declared in this scope"_ or suchlike. – underscore_d Jul 26 '17 at 16:25
  • When I saw this, I was like yeah right... Let me just check-- then woah it was true! :) – xilpex May 22 '20 at 23:17
12

I think you forgot include header <algorithm>

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
-6

You forgot include this header file

#include<vector>

.

parmod
  • 25
  • 4