您的位置:首页 > 其它

STL中set、map的比较函数

2010-08-14 22:52 495 查看
1.如果比较元素不是结构体,重载()符号:

/**
* setCmp,自定义set排序函数。重载"()"操作符
*/
struct setCmp {
bool operator()(const int& a, const int& b) {
return a < b;
}
};


2.如果是结构体,则把比较函数内部,重载<符号:

struct Info {
string name;
float score;
//重载“<”
bool operator<(const Info &a) const {
return a.score < score;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  struct string float