- 1.错误
warning C4018: “<”: 有符号/无符号不匹配
error C3867: “Solution::cmp”: 非标准语法;请使用 “&” 来创建指向成员的指针
error C2672: “std::sort”: 未找到匹配的重载函数
error C2780: “void std::sort(const _RanIt,const _RanIt)”: 应输入 2 个参数,却提供了 3 个
note: 参见“std::sort”的声明
1>已完成生成项目“Project1.vcxproj”的操作 - 失败。
VS2017运行出错:
2.修改方法
要想取类成员函数作为参数,该函数需要是static的,成员函数第一个参数默认是this指针, 加static 静态函数就没有this指针了。
public:
static bool cmp(string& s1, string& s2)
{
return s1 + s2 < s2 + s1;
//if( s1 + s2 < s2 + s1)return ;
}
尝试把这个比较函数写在类的外面,重写了一个cm()的比较函数在可以编译通过