Listing 1: Class person with comparison function objects
//person.h #ifndef __PERSON_H__ #define __PERSON_H__ #include <string> class person { public: //constructors and access functions private: std::string first_; std::string last_; unsigned long id_; //... friend struct less_first; friend struct less_last; friend struct less_id; //... }; struct less_first { bool operator()(person const &lh, person const &rh) const {return lh.first_ < rh.first_;} }; struct less_last { bool operator()(person const &lh, person const &rh) const {return lh.last_ < rh.last_;} }; struct less_id { bool operator()(person const &lh, person const &rh) const {return lh.id_ < rh.id_;} }; //... #endif