std::sort在类中定义时,我无法将该函数与我的自定义比较函数一起使用。
class Test {
private:
vector< vector<int> > mat;
bool compare(vector<int>, vector<int>);
public:
void sortMatrix();
}
bool Test::compare( vector<int> a, vector<int> b) {
return (a.back() < b.back());
}
void Test::sortMatrix() {
sort(vec.begin(), vec.end(), compare);
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息:
error: reference to non-static member function must be called
sort(vec.begin(), vec.end(), compare);
^~~~~~~
Run Code Online (Sandbox Code Playgroud)
然而compare(),当我sortMatrix()在没有任何类的文件 main.cpp 中定义和时,一切正常。我将不胜感激任何帮助和建议。