相关疑难解决方法(0)

使用自定义std :: set比较器

我试图将一组整数中的项的默认顺序更改为lexicographic而不是numeric,并且我无法使用g ++进行以下编译:

file.cpp:

bool lex_compare(const int64_t &a, const int64_t &b) 
{
    stringstream s1,s2;
    s1 << a;
    s2 << b;
    return s1.str() < s2.str();
}

void foo()
{
    set<int64_t, lex_compare> s;
    s.insert(1);
    ...
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

error: type/value mismatch at argument 2 in template parameter list for ‘template<class _Key, class _Compare, class _Alloc> class std::set’
error:   expected a type, got ‘lex_compare’
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

c++ stl

84
推荐指数
5
解决办法
13万
查看次数

标签 统计

c++ ×1

stl ×1