当比较器功能突然出现错误时,我正在为topcoder SRM(623)编码。我之前看到有关比较器功能的问题,但在以下用法中找不到错误:
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";
}
};
错误:
请帮忙!
作为旁边节点, rep 是&#34; for(i = ..; i&lt; ..; i ++)&#34;
的宏答案 0 :(得分:2)
要将成员函数用作比较函数,必须将其声明为static
。