std :: less编译问题

Raj*_*eev 1 c++ templates

我试图使用用户定义的类'A'与模板std :: less.我还有一个函数重写<操作符std::less.此代码未编译.

#include<iostream>
#include<functional>
using namespace std;
class A{
public:
        A(int x=0):a(x){}
        int a;
        bool operator<(const A& ref){
                return a<ref.a;
        }
};
int main()
{
        A a1(1);
        A a2(2);
        std::less<A> comp;
        if( comp(a1,a2)){
                cout<<"less"<<endl;
        }
        else{
                cout<<"more"<<endl;
        }

}
Run Code Online (Sandbox Code Playgroud)

Bal*_*Pal 11

做了

    bool operator<(const A& ref) const{
            return a<ref.a;
    }
Run Code Online (Sandbox Code Playgroud)