I want a function that sort a vector of points by polar angle, but I want to be able to choose the point of origin and the direction (for example, for computing convex hull with Graham scan, you need to sort points by polar angle relatively to the bottommost/leftmost point). To avoid making global variables for the origin and direction, I hid them in a class myComparisonClass. Here is my code:
template<typename TT>
class myComparisonClass {
point<TT> origin;
point<TT> direction;
public:
inline myComparisonClass (point<TT> or, point<TT> dir) : origin(or), direction(dir) {};
bool myComparisonFunction(const point <TT>& a, const point<TT>& b) {
/* ... A function which use a, b, origin and direction ... */
return false;
};
};
template<typename TT>
void mySortByPolarAngle(vector<point<TT> >& P, point<TT> O, point<TT> dir) {
myComparisonClass<TT> obj(O,dir);
bool (myComparisonClass<TT>::* myFunctionPointer)(const point<TT>&, const point<TT>&) = &myComparisonClass<TT>::myComparisonFunction;
sort(P.begin(), P.end(), obj.*myFunctionPointer); /* When trying to use mySortByPolarAngle, compiler says error: invalid use of non-static member function */
}
What is wrong? Is it possible to use "sort" with a comparison function which is a pointer on a non-static member function? Thanks