I have a class Person that has a name and an age.
I have a container class called people that stores a set of persons.
I have created two custom comparators to sort by name and by age.
When I store the set containing Persons in my class (People) how do pass the custom comparator in.
for Example
My comparator looks like this
struct compareByName
{
bool operator()(const Person & Left, const Person & Right)
{
return (Left.getName() < Right.getName());
}
};
in the main if I want to sort a set of persons by name I just do
set<Person, compareByName> peopleByName;
or for age I do
set<Person, compareByAge> peopleByAge;
Where I am having trouble is How do I use this in my people container class I would have something like
class People
{
private:
set<Person, COMPARATOR> m_people;
}
where COMPARATOR could either be by name or age