C++ std list sort with custom comparator that depends on an member variable for the object instance

后端 未结 2 1993
一向
一向 2021-01-13 13:44

Class:

Class:
  private:
    ...
    vector words; 
    vector< list > vints;
  public:
    myFunction(...)

2条回答
  •  无人及你
    2021-01-13 14:15

    With lambdas:

    vints[i].sort([&words](int i, int j) { return words[i] < words[j]; });
    

    With std::bind:

    #include 
    
    //...
    {
      using namespace std::placeholders;
      vints[i].sort(std::bind(&myClass::sortFunc, this, _1, _2));
    }
    

提交回复
热议问题