オペレータ
class LessInt { public: bool operator()(const int& riLeft, const int& riRight) const { return riLeft < riRight; } }; //と定義すれば、 sort(aiTable, aiTable + 5, LessInt()); //と、あたかも、コンストラクタを呼び出しているがごとく見える. sort(a.begin(), a.end(), cmp) //<-- cmpは比較関数 クラスにしていない。
このとき、クラスは入れ子にできるよ.
//コスパ順に. bool operator() (const itemType& left, const itemType& right) { return left.cost*right.weight > right.cost*left.weight; //left.cost*1.0/left.weight > right.cost*1.0/right.weightでもおなじこと。 }