I am writing code to solve the following problem: given the set of numbers x[0] , x[1] , ..., x[N-1] , find a permutation that sorts them in ascending order. In other words, I would like to find a permutation on {0,2, ..., N-1} such as i[0] , i[1] , ..., i[N-1] such that x[i[0]] <= x[i[1]] <= ... <= x[i[N-1]] .
To do this, I saved the vector x and the pointer vector i (originally filled with i[j] = j ) as private members of the class. I also defined a private method as
bool MyClass::compare(size_t s, size_t t) { return (x[s] < x[t]); }
Now I would call std::sort as follows
std::sort(i.begin(), i.end(), compare);
and I expect to get the desired result. But the code does not compile, and I get the following error:
error: no matching function for call to 'sort(std::vector<long unsigned int>::iterator, std::vector<long unsigned int>::iterator, <unresolved overloaded function type>)'
I had to do everything right, and the documentation std::sort mentions that I can pass the function as a comparison operator to std::sort ( http://www.cplusplus.com/reference/algorithm/sort/ )
Thanks for all the help in advance.