使用std :: sort的比较器函数时出现异常错误

时间:2014-06-05 04:29:45

标签: c++ sorting stl

当比较器功能突然出现错误时,我正在为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";
    }
};

错误:

  1. 错误C3867:&#39; CatchTheBeatEasy :: comp&#39;:函数调用缺少参数列表;使用&#39;&amp; CatchTheBeatEasy :: comp&#39;创建指针 构件
  2. 错误C2780:&#39; void std :: sort(_RanIt,_RanIt)&#39; :预计有2个参数--3提供
  3. 请帮忙!

    作为旁边节点, rep 是&#34; for(i = ..; i&lt; ..; i ++)&#34;

    的宏

1 个答案:

答案 0 :(得分:2)

要将成员函数用作比较函数,必须将其声明为static

相关问题