对vector进行sort时,cmp函数的写法

当cmp函数写在类外时,如下:

bool comp(Interval a, Interval b) // 注意comp函数可以为static bool或者bool,返回值为bool类型。a.start& intervals) {
        sort(intervals.begin(), intervals.end(), comp);
    }
};
写在类内时,如下:

class Solution {
private:
    static bool comp(Interval a, Interval b) // 注意comp函数必须为static bool,返回值为bool类型。a.start& intervals) {
        sort(intervals.begin(), intervals.end(), comp);
    }
};


你可能感兴趣的:(C/C++基础知识)