File tree Expand file tree Collapse file tree 4 files changed +11
-11
lines changed Expand file tree Collapse file tree 4 files changed +11
-11
lines changed Original file line number Diff line number Diff line change 69
69
* 自身是常量的指针(常量指针,const pointer)
70
70
* 引用
71
71
* 指向常量的引用(reference to const)
72
- * 没有 const reference,因为引用本身就是 const pointer
72
+ * 没有 const reference,因为引用只是对象的别名,引用不是对象,不能用 const 修饰
73
73
74
74
> (为了方便记忆可以想成)被 const 修饰(在 const 后面)的值不可改变,如下文使用例子中的 ` p2 ` 、` p3 `
75
75
@@ -82,7 +82,7 @@ const 使用
82
82
class A
83
83
{
84
84
private:
85
- const int a; // 常对象成员,只能在初始化列表赋值
85
+ const int a; // 常对象成员,可以使用初始化列表或者类内初始化
86
86
87
87
public:
88
88
// 构造函数
Original file line number Diff line number Diff line change @@ -71,9 +71,9 @@ English
71
71
* Pointer
72
72
* Pointer to const
73
73
* A pointer to a constant itself (const pointer)
74
- * Quote
74
+ * Reference
75
75
* Reference to const
76
- * There is no const reference because the reference itself is a const pointer
76
+ * There is no const reference because the reference is an alias of an object, the reference is not an object
77
77
78
78
> (Think of it for convenience) The value modified by const (after const) cannot be changed, such as ` p2 ` , ` p3 ` in the usage example below
79
79
@@ -87,7 +87,7 @@ const use
87
87
class A
88
88
{
89
89
private:
90
- const int a; // constant object member, can only be assigned in the initialization list
90
+ const int a; // constant object member, can use initialization list or in-class initializer
91
91
92
92
public:
93
93
// Constructor
Original file line number Diff line number Diff line change 62
62
* 自身是常量的指针(常量指针,const pointer)
63
63
* 引用
64
64
* 指向常量的引用(reference to const)
65
- * 没有 const reference,因为引用本身就是 const pointer
65
+ * 没有 const reference,因为引用只是对象的别名,引用不是对象,不能用 const 修饰
66
66
67
67
> (为了方便记忆可以想成)被 const 修饰(在 const 后面)的值不可改变,如下文使用例子中的 ` p2 ` 、` p3 `
68
68
@@ -75,7 +75,7 @@ const 使用
75
75
class A
76
76
{
77
77
private:
78
- const int a; // 常对象成员,只能在初始化列表赋值
78
+ const int a; // 常对象成员,可以使用初始化列表或者类内初始化
79
79
80
80
public:
81
81
// 构造函数
Original file line number Diff line number Diff line change 64
64
* Pointer
65
65
* Pointer to const
66
66
* A pointer to a constant itself (const pointer)
67
- * Quote
67
+ * Reference
68
68
* Reference to const
69
- * There is no const reference because the reference itself is a const pointer
69
+ * There is no const reference because the reference is an alias of an object, the reference is not an object
70
70
71
71
> (Think of it for convenience) The value modified by const (after const) cannot be changed, such as ` p2 ` , ` p3 ` in the usage example below
72
72
@@ -80,7 +80,7 @@ const use
80
80
class A
81
81
{
82
82
private:
83
- const int a; // constant object member, can only be assigned in the initialization list
83
+ const int a; // constant object member, can use initialization list or in-class initializer
84
84
85
85
public:
86
86
// Constructor
@@ -95,7 +95,7 @@ public:
95
95
void function ()
96
96
{
97
97
// object
98
- A b; // ordinary object, can call all member functions, update constant member variables
98
+ A b; // ordinary object, can call all member functions
99
99
const A a; // constant object, can only call constant member functions
100
100
const A *p = &a; // pointer variable, point to a constant object
101
101
const A &q = a; // reference to constant object
You can’t perform that action at this time.
0 commit comments