#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
using namespace std;
class C
{
public:
vector<int> CSort();
bool Func(int x, int y);
private:
vector<int> data;
};
vector<int> C::CSort()
{
vector<int> result(data.size(), 0);
iota(result.begin(), result.end(), 0);
sort(result.begin(), result.end(), Func);
return result;
}
bool C::Func(int x, int y)
{
return (data[x] > data[y]);
}
In my class C
defined as above, I would like to get an order vector of data
with std::sort
using the member function Func
. The result was an error
'C::Func': non-standard syntax; use '&' to create a pointer to member
I believe this has something to do with Why doesn't reference-to-member exist in C++.
However, I cannot come up a proper way to reference this function in std::sort
. How can I implement it correctly?