我正在尝试通过使用自定义比较函数对其调用sort来对结构向量进行排序。
以下是比较和排序功能:
bool Patient::compareByTime(const event &a, const event &b) {
time_t atime, btime;
atime = a.timestamp;
btime = b.timestamp;
return (difftime(atime, btime) > 0);
}
void Patient::calculateStays() {
sort(events.begin(), events.end(), compareByTime);
}
以下是头文件中的struct和vector声明:
class Patient
{
//some stuff omitted here...
struct event {
string facility;
string inpeme;
string complaint;
string admidisc;
time_t timestamp = 0;
};
vector<event> events;
public:
//some stuff omitted here...
bool compareByTime(const event &a, const event &b);
void calculateStays();
};
这些是我无法解决的错误:
'Patient::compareByTime': non-standard syntax; use '&' to create a pointer to member
'sort': no matching overloaded function found
'void std::sort(const _RanIt,const _RanIt)': expects 2 arguments - 3 provided