sortFunction_for_std::vector_in_UserDefinedClass

I have this class:

class QSweep{

public:
QSweep(const vector< vector<double> >& myPoints, const vector< vector<int> >&myEdges);

void intersection(vector< vector<double> >& myPoints, vector< vector<int> >& myEdges);
vector< vector<int> >* sortEdges(vector< vector<double> >& myPoints,
vector<vector<int>>& myEdges);

bool sortx(const vector< vector<int> >& edge1, const vector< vector <int> >& edge2) {
return edge1[0][0]< edge2[0][0];
};
private:
vector< vector<double> > myPoints_;
vector< vector<int> > myEdges_;
};

The constructor creates the desired data structure in this way:
QSweep::QSweep(const vector< vector<double> >& myPoints, const vector< vector<int> >& myEdges){
myPoints_=vector< vector<double> > (myPoints.size(), vector< double >(3,0));
for (unsigned int i=0;i<myPoints.size();i++){
myPoints_[i][0]=myPoints[i][0];
myPoints_[i][1]=myPoints[i][1];
myPoints_[i][2]=myPoints[i][2];
}

myEdges_=vector< vector<int> > (myEdges.size(), vector< int >(2,0));
for (unsigned int i=0;i<myEdges.size();i++){
myEdges_[i][0]=myEdges[i][0];
myEdges_[i][1]=myEdges[i][1];
}
}

giving E.g:
myPoints={{1.0,1.0,2.0},{18.0,4.0,2.0},{5.0,1.0,2.0}};
myEdges={{0,1},{1,2},{0,2}};

I want to have a sort function for myEdges 2-dimensional vector depending on the first coordinate of myPoints given by myEdges[i][0].E.g after sorting myEdges would become
myEdges={{0,1},{0,2},{1,2}} because
myPoints[myEdges[1][0]][0]<myPoints[myEdges[2][0]][0].

I tried:
bool sortx(const vector<int> & edge1,const vector<int> & edge2) {
return myPoints_[edge1[0][0]< myPoints_[edge2[0][0];
};
in the public member of QSweep
with the call:
int main(){
...
sort(myVector1.begin(),myVector1.end(),sortx);
}
but I keep having the same error (even if I modified something):
sort.cpp: In static member function 'static bool QSweep::sortx(const std::vector<int, std::allocator<int> >&, const std::vector<int, std::allocator<int> >&)':
sort.cpp:47: error: invalid use of member 'QSweep::myPoints_' in static member function
sort.cpp:25: error: from this location
sort.cpp:47: error: invalid use of member 'QSweep::myPoints_' in static member function
sort.cpp:25: error: from this location
sort.cpp: In function 'int main()':
sort.cpp:106: error: 'sortx' was not declared in this scope

If I used change it in:
bool sortx(const vector<int> & edge1,const vector<int> & edge2) {
return edge1[0]< edge2[0];
};

I have never used vector containers before and clearly I dont surely understand how they work.
Can I just use also the members of the class myPoints when defining the sortx function.
And even without it I can see I still have an error.
Maybe the call to the sort is not good?
what am I possibly doing wrong?
Thank you in advance for your suggestions (remarks or comments, documentation on subject).
The compiler error does not match the code you've posted. Can you post the code that generates that compile error? Also, use code tags (the # to the right) so it is formatted nicely.
Topic archived. No new replies allowed.