首页 > 其他 > 详细

const type& 与 type& 的区别

时间:2014-03-26 05:09:39      阅读:403      评论:0      收藏:0      [点我收藏+]

const type& 与 type& 是C/C++编程中容易混淆的两个知识点,现在以 cont int& 与 int& 为例讲解:

1.int& 讲解

   int a = 10;

   int& b = a;

   a的值可以通过a改变,也可以通过b改变

2.const int& 讲解

   int a = 10;

   const int& b = a;

   a的值只能通过a改变,不能通过b改变

3.const int a = value 的引用只能为 const int b& = a

   因为a的值是无法改变的,所以其引用也无法改变a的值,所以只能为常引用

   

const type& 与 type& 的区别,布布扣,bubuko.com

const type& 与 type& 的区别

原文:http://www.cnblogs.com/wss-is-knight/p/3624164.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!