我的问题:
在写仿函数的时候我是这样写的:

//仿函数
class MyCompare
{public:bool operator()(int v1, int v2)//重载(){return v1 > v2;}
};

报错:

已启动生成…
1>------ 已启动生成: 项目: STL, 配置: Debug Win32 ------
1>41set容器-排序.cpp
1>D:\visual studio\Microsoft Visual Studio2019Community\VC\Tools\MSVC\14.28.29910\include\xutility(1622,19): error C3848: 具有类型“const MyCompare”的表达式会丢失一些 const-volatile 限定符以调用“bool MyCompare::operator ()(int,int)”
1>D:\visual studio\Microsoft Visual Studio2019Community\VC\Tools\MSVC\14.28.29910\include\xutility(1621): message : 查看对正在编译的函数 模板 实例化“bool std::_Debug_lt_pred<const MyCompare&,const _Kty&,const _Keyty&,0>(_Pr,_Ty1,_Ty2) noexcept(<expr>)”的引用
1>        with
1>        [
1>            _Kty=int,
1>            _Keyty=int,
1>            _Pr=const MyCompare &,
1>            _Ty1=const int &,
1>            _Ty2=const int &
1>        ]
1>D:\visual studio\Microsoft Visual Studio2019Community\VC\Tools\MSVC\14.28.29910\include\xtree(1002): message : 查看对正在编译的函数 模板 实例化“std::_Tree_find_result<std::_Tree_node<int,std::_Default_allocator_traits<_Alloc>::void_pointer> *> std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::_Find_lower_bound<_Key>(const _Keyty &) const”的引用
1>        with
1>        [
1>            _Alloc=std::allocator<int>,
1>            _Kty=int,
1>            _Pr=MyCompare,
1>            _Key=int,
1>            _Keyty=int
1>        ]
1>D:\visual studio\Microsoft Visual Studio2019Community\VC\Tools\MSVC\14.28.29910\include\xtree(1009): message : 查看对正在编译的函数 模板 实例化“std::_Tree_find_result<std::_Tree_node<int,std::_Default_allocator_traits<_Alloc>::void_pointer> *> std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::_Find_lower_bound<_Key>(const _Keyty &) const”的引用
1>        with
1>        [
1>            _Alloc=std::allocator<int>,
1>            _Kty=int,
1>            _Pr=MyCompare,
1>            _Key=int,
1>            _Keyty=int
1>        ]
1>D:\visual studio\Microsoft Visual Studio2019Community\VC\Tools\MSVC\14.28.29910\include\xtree(1344): message : 查看对正在编译的函数 模板 实例化“std::pair<std::_Tree_node<int,std::_Default_allocator_traits<_Alloc>::void_pointer> *,bool> std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::_Emplace<int>(int &&)”的引用
1>        with
1>        [
1>            _Alloc=std::allocator<int>,
1>            _Kty=int,
1>            _Pr=MyCompare
1>        ]
1>D:\visual studio\Microsoft Visual Studio2019Community\VC\Tools\MSVC\14.28.29910\include\xtree(1344): message : 查看对正在编译的函数 模板 实例化“std::pair<std::_Tree_node<int,std::_Default_allocator_traits<_Alloc>::void_pointer> *,bool> std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::_Emplace<int>(int &&)”的引用
1>        with
1>        [
1>            _Alloc=std::allocator<int>,
1>            _Kty=int,
1>            _Pr=MyCompare
1>        ]
1>C:\Users\matebook\Desktop\C++练习\STL\41set容器-排序.cpp(35): message : 查看对正在编译的函数 模板 实例化“std::pair<std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<int>>>,bool> std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::insert<false,0>(int &&)”的引用
1>        with
1>        [
1>            _Kty=int,
1>            _Pr=MyCompare,
1>            _Alloc=std::allocator<int>
1>        ]
1>C:\Users\matebook\Desktop\C++练习\STL\41set容器-排序.cpp(35): message : 查看对正在编译的函数 模板 实例化“std::pair<std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<int>>>,bool> std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::insert<false,0>(int &&)”的引用
1>        with
1>        [
1>            _Kty=int,
1>            _Pr=MyCompare,
1>            _Alloc=std::allocator<int>
1>        ]
1>已完成生成项目“STL.vcxproj”的操作 - 失败。
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

const MyCompare

【C++】一次遇到的需要加入const属性的情况相关推荐

  1. 函数模板的特例化(专用化)以及类型含有const的特殊情况

    一.函数模板特例化: 1 #include <iostream> 2 #include <typeinfo>3 using namespace std;4 5 template ...

  2. C++:const分配内存情况分析

    //1.局部变量const int a = 10 ;  int * p = &a //分配临时内存  指针不可修改 const int a = 10 ; 这句话表示const int a是存放 ...

  3. 用汇编的眼光看C++(之const属性)

    [ 声明:版权所有,欢迎转载,请勿用于商业用途.  联系信箱:feixiaoxing @163.com] const是C/C++语言中的关键字,但是如果用的好,可以极大地提高代码的健壮性.一般来说co ...

  4. const在函数前与函数后的区别 [转]

    [转] http://blog.csdn.net/clozxy/article/details/5679887 一   const基础           如果const关键字不涉及到指针,我们很好理 ...

  5. C++中的const关键字(zz)

    [补充]mutable关键字 有时我们希望类的数据成员即使在const成员函数中,依然是可以修改的,这时就可以把它们声明为mutable来实现.这样的应用,比如记录各种操作的调用次数,这时,即使在co ...

  6. const在函数声明中的应用(转)

    1.在一个函数声明中,const 可以修饰函数的返回值,或某个参数:对于成员函数,还可以修饰是整个函数.有如下几种情况,以下会逐渐的说明用法: A& operator=(const A& ...

  7. c++语言关键字大全,C++语言const 关键字使用方法图文详解

    之前一直在学习C/C++,关于const的使用,这里出现一点,那里出现一点.知识用时方恨少,这一段时间正好各种笔试题,其中关于const的用法也是层出不穷,所以疲于在书本上各种翻,这里汇总一下,加深自 ...

  8. C++中的const成员函数介绍

     List { 02 private: 03      Node * p_head; 04      int length; 05      -- 06 Public: 07      int Get ...

  9. const int *,const int * const和int const *有什么区别?

    我总是搞砸了如何正确使用<code>const int* , const int * const和int const * . 是否有一组规则定义您可以做什么和不能做什么? 我想知道在分配, ...

  10. typedef,static,const用法

    一.typedef主要功能是定义一个已存在类型的别名,但是和宏并存 宏与typedef区别 1.宏定义只是简单的字符串替换 2.typedef定义的类型是类型的别名,typedef后面是一个整体声明, ...

最新文章

  1. ​中国开启开源新纪元
  2. python 天气预报
  3. 【Ansible 文档】【译文】模式
  4. Apache Hook机制解析(中)——细节讨论
  5. ASP.NET控件开发基础5
  6. P2634 [国家集训队]聪聪可可(树形dp)
  7. cesium事件简单全面描述
  8. 每日一题(38)—— 一个32位的机器,该机器的指针是多少位?
  9. numpy常用函数(更新中)
  10. c语言删除字符串s中与c相同的字符串,看不懂这段c语言代码的思路,目的是删除字符串1中与字符串2相同的字符...
  11. python request 等待网页加载_用Python开发爬虫,看这篇文章就够了
  12. java执行脚本命令(shell脚本或cmd脚本)
  13. sql date 函数_SQL Server DATE函数–终极指南
  14. hdu 1890 Robotic SortI(splay区间旋转操作)
  15. ICML 2019 | 强化学习用于推荐系统,蚂蚁金服提出生成对抗用户模型
  16. w10系统服务器启动失败,三种方法教你解决Win10系统Apache启动失败问题
  17. MzTreeView节点树(梅花雪)
  18. 联想便携式计算机720s使用什么硬盘盒,8代酷睿加持!联想720S轻薄本评测
  19. 什么是云监控,云监控工具
  20. 4g物联网卡赋能智能设备 加快社会智能化进程

热门文章

  1. excel多列数据生成图分类有间隔
  2. 人脸重建github源码总结
  3. Atitit 代码之美读后感目录内容简介 · · · · · · 1目录 1作者简介 · · · · · · 2ati评价案例法总结 内容简介 · · · · · ·《
  4. Atitit smp prj 项目简化方法总结 目录 第一章 俩大原则准则 1 第一节 极简主义原则 + 自由主义原则 1 第二章 简单化架构 1 第一节 简单语言php vs java 1 第二
  5. atitti 提升稳定性的艺术之程序代码级别稳定性的艺术 attialx著 艾提拉著 s420.docx 1. 前言 1 2. 为什么会发生稳定性问题 1 2.1. 单点故障(单点故障率较高) 1
  6. Atitit 把项目外包的面临的风险attilax总结
  7. Atitit 图像处理 常用8大滤镜效果 Jhlabs 图像处理类库 java常用图像处理类库
  8. Atitit selenium3 新特性
  9. paip.论程序断点的类型以及设置总结
  10. paip.C#.NET图形按钮制做