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; } };