utilities(C/C++)(二)
1287 ワード
utilities(C/C++)
説明言語 ソート基準(sorting criterion)
いやだからか、できないからか、一般的なoperator<を使ってこれらのオブジェクトをソートするのではなく、特定のルール(通常はいくつかのメンバー関数に基づいている)でソートしなければならないので、function objectsが活躍する舞台です.
説明言語
index out of range.
:下標越境いやだからか、できないからか、一般的なoperator<を使ってこれらのオブジェクトをソートするのではなく、特定のルール(通常はいくつかのメンバー関数に基づいている)でソートしなければならないので、function objectsが活躍する舞台です.
class Person
{
public:
std::string firstname() const;
std::string secondname() const;
...
}
class PersonSortCriterion
{
public:
bool operator() (const Person& left, const Person& right) const
{
return left.lastname() < right.lastname() || (left.lastname() == right.lastname() && left.firstname() < right.firstname());
}
}