In this situation, you must give a valid stringent weak ordering comparison for the type held in the queue, Person.
The default value is std::lessT>, which translates to something like operator.
This is dependent on its own stored type having one.
So, if you were to put it into action,
bool operator<(const Person& lhs, const Person& rhs);
it should work without any further changes. The implementation could be
bool operator<(const Person& lhs, const Person& rhs)
{
return lhs.age < rhs.age;
}
If the type lacks a natural "less than" comparison, it is preferable to give your own predicate rather than the default std::lessPerson>.
As an example,
struct LessThanByAge
{
bool operator()(const Person& lhs, const Person& rhs) const
{
return lhs.age < rhs.age;
}
};
then instantiate the queue like this:
std::priority_queue<Person, std::vector<Person>, LessThanByAge> pq;
Concerning the usage of std::greaterPerson> as a comparator, this would employ the equivalent of operator> and result in the creation of a queue with the priority inverted in comparison to the default situation.
It would need the availability of an operator> capable of operating on two Person instances.