Reputation: 631
The code below will not compile. There is an error on the 2nd to the last line (nth_element...). It seems to be related to the comparator. Compiler claims "term does not evaluate to a function taking 2 arguments". How do I fix the compile error?
struct Result {
Result(unsigned int id, double result);
bool cmp(const Result &a, const Result &b) const;
unsigned int id;
double result;
};
Result::Result(unsigned int id, double result) {
this->id = id;
this->result = result;
}
bool Result::cmp(const Result &a, const Result &b) const {
if(a.result < b.result) {
return true;
}
return false;
}
//25th-percentile
int index = (int) ((buffer.size()+1.0)/4.0 - 0.499);
vector<Result>::iterator itrindex = buffer.begin() + index;
nth_element(buffer.begin(), itrindex, buffer.end(), &Result::cmp);
double twentyfifthperc = buffer[index].result;
Upvotes: 0
Views: 73
Reputation: 218005
bool cmp(const Result &a, const Result &b) const;
should be
static bool cmp(const Result &a, const Result &b);
Upvotes: 3