Reputation: 112
I was coding for a topcoder SRM(623) when suddenly the comparator function started giving errors. I saw earlier questions asked on the comparator function but cannot find the error in the following usage:
class CatchTheBeatEasy
{
public:
bool comp( p p1, p p2){ return (p1.time>p2.time); }
string ableToCatchAll(vector <int> x, vector <int> y)
{
vector < p > points;
int i=0;
rep (i,0,x.size())
{
p temp;
temp.time=y[i];
temp.x=x[i];
points.push_back(temp);
}
sort(points.begin(),points.end(),comp); //ERROR Here
int curx=0, curtime=0;
rep (i,0,points.size())
{
if ( points[i].time-curtime < abs(points[i].x-curx) )
return "Not Able To Catch";
else
{
curtime += abs(points[i].x-curx);
curx=points[i].x;
}
}
return "Able To Catch";
}
};
Errors:
Please help!
As a side node, rep is a macro for "for(i=..;i<..;i++)"
Upvotes: 1
Views: 858
Reputation: 308530
To use a member function as a comparison function, it must be declared static
.
Upvotes: 2