自定义类型一定要指定插入规则
通过仿函数或者重载<操作符
举个例子:按年龄降序,再按身高降序排序
1.仿函数
#include<iostream>
#include<set>
#include<string>
using namespace std;
class Person
{
public:
Person(string name, int age, float height)
{
m_name = name;
m_age = age;
m_height = height;
}
public:
string m_name;
int m_age;
float m_height;
};
class Compare
{
public:
bool operator()(const Person& p1,const Person& p2) const//一定要定义为常函数,且参数需要限定为const
{
if (p1.m_age == p2.m_age)
return p1.m_height > p2.m_height;
else
return p1.m_age > p2.m_age;
}
};
void Print