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
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.
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.
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 .
You forgot to #include <algorithm>
.
I think you forgot include header <algorithm>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With