#include <iostream>
#include <set>
#include <string>
using namespace std;
class Teacher
{
public:
Teacher(string name, int age)
{
this->name = name;
this->age = age;
}
~Teacher(){}
public:
string name;
int age;
};
//伪函数
struct FuncTeacher
{
bool operator()(const Teacher &left, const Teacher &right) const
{
if (left.age<right.age)
{
return true;
}
else
{
return false;
}
}
};
int main()
{
set<Teacher,FuncTeacher> s;
Teacher t1("t1", 20);
Teacher t2("t2", 15);
Teacher t3("t3", 30);
Teacher t4("t4", 18);
s.insert(t1);
s.insert(t2);
s.insert(t3);
s.insert(t4);
for (set<Teacher, FuncTeacher>::iterator it = s.begin(); it != s.end(); it++)
{
cout << (*it).age << endl;
}
}