void print1(int a)
{
cout<<a<<endl;
} void print2(const int& a)
{
cout<<a<<endl;
} void print3(int& a)
{
cout<<a<<endl;
} int main()
{
int a = ;
int& b = a;
const int& c = a; print1(a);
print1(b);
print1(c); print2(a);
print2(b);
print2(c); print3(a);
print3(b);
print3(c); return ;
}

编译以上代码,仅print3(c)处报错:

error: C2664: “void print3(int &)”: 无法将参数 1 从“const int”转换为“int &”转换丢失限定符

因此,const引用可以给非const引用赋值,而反过来不行,所以编写接口参数时,尽量使用const引用

最新文章

  1. Programming Learning - Based on Project
  2. Socket通讯
  3. JAVA基础知识之JDBC——编程步骤及执行SQL
  4. Selenium操作页面元素
  5. 为YAESU FT-817ND 增加频谱功能
  6. oracle vm virtualbox 如何让虚拟机可以上网
  7. c语言结构体保存并输出学生信息
  8. 网站分析统计JS源码分享
  9. 51nod建设国家
  10. nginx学习六 高级数据结构之双向链表ngx_queue_t
  11. Chapter 2.策略模式
  12. IOS小技巧——使用FMDB时如何把一个对像中的NSArray数组属性存到表中
  13. 数据存储之HTTP Cookie
  14. 新概念英语(1-95)Tickets,please!
  15. (转)JMeter学习逻辑控制器
  16. 4.11Python数据处理篇之Matplotlib系列(十一)---图例,网格,背景的设置
  17. VB 半透明窗体
  18. css的小知识
  19. Spring的介绍与搭建
  20. Visual Studio Code 写Python 代码

热门文章

  1. 网络助手之NABCD
  2. Struts2框架学习
  3. [百度贴吧]10GB 通信线缆
  4. 我的虚拟机中的 centOS 连不了网了
  5. mybatis中@Param的使用
  6. vue element 新增、编辑类Dialog公用函数
  7. 牛客OI赛制测试赛3 解题报告
  8. C++ STL 常用查找算法
  9. 【2018ICPC沈阳】
  10. [BZOJ1500][NOI2005]维修数列 解题报告 Splay