I have followed the solution given here to sort a vector of pairs.
And I get
linear_problem.h:275:
error: no matching function for call to
‘sort(std::vector<std::pair<int, double> >::iterator,
std::vector<std::pair<int, double> >::iterator, <unresolved overloaded
function type>)’
std::sort(data.begin(), data.end(), compareFunc);
The class with the code is:
class Coefficients{
private:
std::vector<std::pair<int, double>> data;
public:
Coefficients(){}
bool compareFunc(const std::pair<int, double> &a, const std::pair<int, double> &b){
return a.first > b.first;
}
void sort(){
std::sort(data.begin(), data.end(), compareFunc);
}
};
I have no idea of what can be wrong since the code is quite like the example.
compareFunc()
is a member function and requires an instance ofCoefficients
to be called.You can make it a
static
class member function to solve that problem: