摘要: 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的值,所以只能为常引用 阅读全文
posted @ 2014-03-25 21:19 瓦尔登湖畔的小木屋 阅读(1155) 评论(0) 推荐(0) 编辑
摘要: Reader/Writer继承关系图RandomAccess继承关系图 阅读全文
posted @ 2014-03-25 20:59 瓦尔登湖畔的小木屋 阅读(657) 评论(0) 推荐(1) 编辑
摘要: type * const 与 const type * 是在C/C++编程中特别容易混淆的两个知识点,现在就以 int * const 和 const int * 为例来简略介绍一下这两者之间的区别。1.int * const 讲解 int a = 20; int * const b = &a; b代表一个指向a变量存储空间的int *常量指针,由于b是一个常量指针,因此其指针值无法改变,亦即无法指向其他的存储空间,但其指向的存储空间的值可以通过 *b = newValue / a = newValue 改变。示例代码如下: 1 #include 2 3 using namespace 阅读全文
posted @ 2014-03-25 20:58 瓦尔登湖畔的小木屋 阅读(1017) 评论(0) 推荐(0) 编辑