I have a function in a sorting header for mergeSort
This is my code:
template
void mergeSort(vector<Comparable> & a, vector<Comparable> & tmpArray, int left int right, Comparator cmp)
{
if (cmp(left,right))
{
int center = (left + right) / 2;
mergeSort(a, tmpArray, left, center);
mergeSort(a, tmpArray, center + 1, right);
merge(a, tmpArray, left, center + 1, right);
}
}
I want to use this comparator and pass in the parameters in my mainDriver.cpp
class CompareXCoordinate {
public:
bool operator()(const Point & p1, const Point & p2) const
{
return (p1.getX() < p2.getX());
}
};
Currently I am passing it like this:
Points is vector of Point objects tempArr is an empty vector
mergeSort(points, tempArr, points.begin(), points.end(), Point::CompareXCoordinate::operator())
I get an error of C3867: non-standard syntax, use & to create pointer to member
Is that the proper way to pass a comparator or is it a different syntax?