关于sort的比较函数的static 声明

来源:互联网 发布:金蝶kis数据字典 编辑:程序博客网 时间:2024/06/04 18:42

在进行编写sort函数的比较函数时,

     bool compare(string str1,string str2){
        string comp1=str1+str2;
        string comp2=str2+str1;
        
        return comp1 < comp2;
    }

只是简单的外部声明,也没有类的引用,在VS上运行时正确,但是在其它平台上出现报错:

reference to non-static member function must be called sort(temp.begin(),temp.end(),compare);

意思是sort的调用必须是静态成员,之后声明为static后就正确了。

但是官方文档的例子没有这样的说明,

原创粉丝点击