Sort function does not work with function object created on stack?

后端 未结 5 1821
旧时难觅i
旧时难觅i 2021-01-26 17:06
#include
#include
#include
class Integer
    {
public:
    int m;
    Integer(int a):m(a){};
    };
class CompareParts
            


        
5条回答
  •  有刺的猬
    2021-01-26 17:23

    obj2 is not a BinaryPredicate and is invalid as the third parameter to std::sort

    obj2 needs to be something like

    // Return whether first element is greater than the second
    bool UDgreater ( int elem1, int elem2 )
    {
       return elem1 > elem2;
    }
    

    or the functor type used by obj1.

提交回复
热议问题