zoukankan      html  css  js  c++  java
  • STL_函数对象01

    1、自定义函数对象

      1.1、简单例子: 

      //函数对象
      struct StuFunctor
      {
        bool operator() (const CStudent &stu1, const CStudent &stu2)
        {
          return (stu1.m_iID<stu2.m_iID);
        }
      }

      1.2、自定义 函数对象 使用

        set<CStudent, StuFunctor> setStu;

    2、

    ZC: 有些时候 函数指针 可以当做函数对象来用。(STL算法里面有这样的情况)

    ZC: STL算法里面 较常使用 函数对象

    3、

    ZC: 函数对象 是一个 struct

    ZC: 函数对象的 返回值,一定是 bool 吗?

    ZC: 函数对象的 参数类型 是变化的

    ZC: 函数对象的 参数个数 一定是2个吗?

    4、默认 函数对象

      less<T>

      greater<T>

      4.1、简单例子:

        “

        set<int,greater<int>> setIntB;
        setIntB.insert(3);
        setIntB.insert(1);
        setIntB.insert(5);
        setIntB.insert(2);

        此时容器setIntB就包含了按顺序的5,3,2,1元素

      ”

    5、

    6、

  • 相关阅读:
    如何快速转载CSDN及博客园中的博客
    Ubuntu18.04连不网 报"有线连接未托管"
    Ubuntu18.04的网络配置
    vim基本操作
    Git更新远程仓库代码到本地(转)
    POJ 3253 Fence Repair
    POJ 2503 Babelfish
    POJ 2002 Squares
    POJ 1840 Eqs
    POJ 3274 Gold Balanced Lineup
  • 原文地址:https://www.cnblogs.com/cppskill/p/5438560.html
Copyright © 2011-2022 走看看