This is my code:
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
class A {
struct CompareMe {
bool operator() (const string*& s1, const string*& s2) const { return true; }
};
void f() {
CompareMe comp;
vector<string*> v;
min_element(v.begin(), v.end(), comp);
}
};
And this is the error:
error: no match for call to ‘(A::CompareMe) (std::string*&, std::string*&)’
test.cpp:7: note: candidates are: bool A::CompareMe::operator()(const
std::string*&, const std::string*&) const
I feel that there is some syntax defect, but can’t find out which one. Please, help!
Your placement of
constis wrong. AT*&cannot be implicitly converted to aconst T*&. Tryinstead.
Or just pass by value (thanks Mike):
which will be more efficient for simple objects like a pointer, if the compiler uses a standard ABI.