大菜鸟学习记 2023-08-15 18:01 采纳率: 100%
浏览 5
已结题

关于#c++#的问题:C++中set容器,利用仿函数改变排序规则

C++中set容器,利用仿函数改变排序规则,insert报错

In template: static assertion failed due to requirement 'is_invocable_v<const MyCompare &, const int &, const int &>': comparison object must be invocable as const error occurred here in instantiation of member function 'std::_Rb_tree<int, int, std::_Identity, MyCompare>::_S_key' requested here in instantiation of member function 'std::_Rb_tree<int, int, std::_Identity, MyCompare>::_M_get_insert_unique_pos' requested here in instantiation of function template specialization 'std::_Rb_tree<int, int, std::_Identity, MyCompare>::_M_insert_unique' requested here in instantiation of member function 'std::set<int, MyCompare>::insert' requested here

img

  • 写回答

2条回答 默认 最新

  • 路漫漫~Kevin 2023-08-15 18:46
    关注
    
    class MyCompare
    {
    public:
        bool operator()(const int& v1, const int& v2) const
        {
            return v1 > v2;
        }
    };
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 10月5日
  • 已采纳回答 9月27日
  • 创建了问题 8月15日

悬赏问题

  • ¥20 遥感植被物候指数空间分布图制作
  • ¥15 安装了xlrd库但是import不了…
  • ¥20 Github上传代码没有contribution和activity记录
  • ¥20 SNETCracker
  • ¥15 数学建模大赛交通流量控制
  • ¥15 为什么我安装了open3d但是在调用的时候没有报错但是什么都没有发生呢
  • ¥50 paddleocr最下面一行似乎无法识别
  • ¥15 求某类社交网络数据集
  • ¥15 靶向捕获探针方法/参考文献
  • ¥15 很抱歉出现错误word不能启动(24),如何解决?