Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::find 'error no matching function'

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

like image 769
chiva Avatar asked Feb 06 '14 17:02

chiva


People also ask

How to fix no matching function for call to c++?

We mismatch the parameters to the function. We might be required to give the matched parameter to the specified method. Or we have to add a new function with the same data type. After checking and adding suitable parameters to the function in the program, the error, 'no matching function for a call' will be resolved.

Is std :: find slow?

std::equal_range on bidirectional iterators is extremely slow, because it has to walk step by step through the range. The std::set. find method, on the other hand, uses the tree structure of std::set to find the element really fast. It can, basically, get midpoints of a range really fast.

What does std :: find do?

std::find. Returns an iterator to the first element in the range [first,last) that compares equal to val . If no such element is found, the function returns last .


2 Answers

You forgot to #include <algorithm>.

like image 146
Kerrek SB Avatar answered Sep 22 '22 14:09

Kerrek SB


I think you forgot include header <algorithm>

like image 38
Vlad from Moscow Avatar answered Sep 21 '22 14:09

Vlad from Moscow