0
以下のコードはコンパイルされません。 2行目から最後の行にエラーがあります(nth_element ...)。これはコンパレータに関連しているようです。コンパイラは "termは2つの引数を取る関数に評価されない"と主張している。コンパイルエラーを修正するにはどうすればよいですか?C++ベクトルイテレータnth_elementコンパイルエラー
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;
は、おそらく説明を追加することが参考になるはずです。 – jodag
Jarod42さん、ありがとうございました。 – PentiumPro200