sort(myVector1.begin(),myVector1.end(),sortx);
You need to tell std::sort
, which you are using inside main
, if you are going to use this form, that you want to use the member function sortx
. Try:
sort(myVector1.begin(),myVector1.end(), std::mem_fun_ref(&QSweep::sortx));
Also, your sort function takes incorrect parameters:
bool sortx(const vector< vector >& edge1, const vector< vector >& edge2)
To sort your vector
of vector
of int
s your sortx
should take:
bool sortx(const vector<int>& edge1, const vector<int>& edge2)
Also, note that you cannot use multiple indexes with a vector of vector as you can with multidimensional arrays. I think you have over complicated your problem :)
Here is a simplified solution for sorting your tuple Point type:
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>
using namespace std;
template <class _MyType>
struct Point {
Point() {}
void insert(_MyType const& p) {
_pts.push_back(p);
}
bool operator<(Point<_MyType> const& o) {
return _pts[ 0 ] < o._pts[ 0 ];
}
private:
typename vector<_MyType> _pts;
};
int main()
{
Point<int> p;
p.insert(1); p.insert(0); p.insert(2); // {1, 0, 2}
Point<int> q;
q.insert(-1); q.insert(10); q.insert(2); // {-1, 10, 2}
vector<Point<int> > sweep;
sweep.push_back(p);
sweep.push_back(q);
sort(sweep.begin(), sweep.end());
return 0;
}