仿函数1-当排序规则

#include 
#include 
#include 

using namespace std;

class Person{

public:
	Person(const std::string& first_name, const std::string& last_name) :
		first_name_(first_name), last_name_(last_name)
	{}
	std::string firstname()  const { return first_name_;}
	std::string lastname() const {return last_name_;}
private:
	std::string first_name_;
	std::string last_name_;
};


class PersonSortCriterion{
public:
	bool operator()(const Person& lhs, const Person& rhs) {

		return lhs.lastname() < rhs.lastname() 
			|| (!(lhs.lastname() < rhs.lastname()) && lhs.firstname() < rhs.firstname());
	}
};

int _tmain(int argc, _TCHAR* argv[])
{
	typedef std::set PersonSet;
	PersonSet ps;
	ps.insert(Person("ketty","Yang"));
	ps.insert(Person("ketty", "Xang"));
	ps.insert(Person("ketty", "Wang"));
	return 0;
}

你可能感兴趣的