小编man*_*smi的帖子

如何在C++中使用自定义比较器创建std :: set?

如何创建一组对,其中的元素(对)使用自定义bool函数进行排序?我写

set <pair<int,int>,compare> myset;
Run Code Online (Sandbox Code Playgroud)

并得到错误:参数2处的类型/值不匹配,预期类型,得到"比较"

我把"比较"定义为

bool compare(pair <int,int> g1, pair <int,int> g2)
{
    return (g1.second-g1.first > g2.second-g2.first);
}
Run Code Online (Sandbox Code Playgroud)

而且当然

#include <vector>
#include <set>
Run Code Online (Sandbox Code Playgroud)

c++ set comparator std-pair

1
推荐指数
1
解决办法
3733
查看次数

标签 统计

c++ ×1

comparator ×1

set ×1

std-pair ×1