【发布时间】:2016-03-02 17:04:04
【问题描述】:
我正在尝试按类的特定参数对指针列表进行排序,为此工作了将近一个小时。它给了我错误:
/src/ClassifyById.cpp:26:25: error: no matching function for call to
‘std::list<Worker*>::sort(<unresolved overloaded function type>)’
在搜索时我发现了这个: Problem sorting a list of pointers
但这不是我的情况,我不明白为什么我的代码不起作用。据我所知,我不能在这个作业中使用仿函数。 这是我的代码:
#include "ClassifyById.h"
#include "Worker.h"
#include <algorithm>
void ClassifyById::classify(list<Worker*> toClassify) {
toClassify.sort(compare); //ERROR###
}
bool ClassifyById::compare(Worker* a, Worker* b){
return (a->getId() < b->getId());
}
为什么不编译?
【问题讨论】: