Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 稳定\u排序缺少运算符-已定义自定义比较函数_C++ - Fatal编程技术网

C++ 稳定\u排序缺少运算符-已定义自定义比较函数

C++ 稳定\u排序缺少运算符-已定义自定义比较函数,c++,C++,我称之为 bool cmpNAME(const PlayerCard& a, const PlayerCard& b){ return (a.Name < b.Name);//Name is std::string } list<PlayerCard> tmp; //fill tmp stable_sort(tmp.begin(), tmp.end(), cmpNAME);//error at this line boolcmpname(const P

我称之为

bool cmpNAME(const PlayerCard& a, const PlayerCard& b){
    return (a.Name < b.Name);//Name is std::string
}
list<PlayerCard> tmp;
//fill tmp
stable_sort(tmp.begin(), tmp.end(), cmpNAME);//error at this line
boolcmpname(const PlayerCard&a、const PlayerCard&b){
return(a.Name
编译器给了我一个错误,那个就是它缺少的运算符——用于PlayerCard,但为什么我为这个结构定义了comparator呢

我得到的错误:
/usr/include/c++/4.8/bits/stl_algo.h|3508 |错误:与“operator-”不匹配(操作数类型为“std:_List_iterator”和“std:_List_iterator”)


我想要实现的是比较名称,如果它们相同,则按我将它们放入列表的顺序进行比较。

std::stable_sort
需要一个随机访问迭代器<代码>列表的迭代器不是随机访问的


使用。

发布错误问题时,请包含实际、完整且未经编辑的错误日志。此外,如果编译器抱怨某些行,并且文件很长,请发布保留行号的重要部分,我们更容易发现实际的错误。我需要排序stable@lllook是什么让你认为
std::list::sort
不稳定?