클래스 내에 정의 된 경우 내 맞춤 비교 함수로 std :: sort 함수를 사용하는 데 문제가 있습니다.std :: sort 함수와 사용자 정의 비교 함수 결과 오류 : 비 정적 멤버 함수에 대한 참조를 호출해야합니다.
error: reference to non-static member function must be called
sort(vec.begin(), vec.end(), compare);
^~~~~~~
내가 그러나 비교 정의 할 때()와 파일 MAIN.CPP에서 sortMatrix() 모든 클래스하지 않고, 모든 것이 잘 작동 :
class Test {
private:
vector< vector<int> > mat;
bool compare(vector<int>, vector<int>);
public:
void sortMatrix();
}
bool Field::compare(vector<int> a, vector<int> b) {
return (a.back() < b.back());
}
void Test::sortMatrix() {
sort(vec.begin(), vec.end(), compare);
}
나는 다음과 같은 오류 메시지가 나타납니다. 나는 어떤 도움이나 제안을 주셔서 감사합니다.
멤버 함수를'Test' 클래스 호출 연산자로 바꾸고'Test'를'sort()'에 대신 쓸 수는 없습니다 :'sort (vec.begin(), vec.end(), Test); ' –