I want to use the function nth_element
with my own sorting function (which should have access to the data of the object) within a class. Currently, I am doing the following:
class Foo
{
public:
glm::vec3 *points;
int nmbPoints;
bool idxPointCompareX(int a, int b);
void bar();
}
bool Foo::idxPointCompareX(int a, int b)
{return points[a].x < points[b].x;)
void Foo::bar()
{
stl::vector<int> idxPointList;
for(int i = 0; i < nmbPoints; i++) idxPointList.push_back(i);
stl::nth_element(idxPointList.first(),idxPointList.first()+nmbPoints/2,idxPointList.end(), idxPointCompareX);
}
Of course, this did not work and I got the error: "reference to non-static member function must be called". After that, I had a look at Reference to non-static member function must be called, How to initialize std::function
with a member-function? and some other questions on here. I understand why this did not work, but I'm unsure how to solve this.
Can someone help me and tell me how to solve this problem?