我是靠谱客的博主 忧虑板栗,这篇文章主要介绍utilities(C/C++)(二),现在分享给大家,希望可以做个参考。

utilities(C/C++)

说明性语言

  • index out of range.:下标越界

排序准则(sorting criterion)

或许因为不想,或许因为不能,无法使用一般的 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());
    }
}

最后

以上就是忧虑板栗最近收集整理的关于utilities(C/C++)(二)的全部内容,更多相关utilities(C/C++)(二)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(147)

评论列表共有 0 条评论

立即
投稿
返回
顶部