Skip to content

Commit 456ced1

Browse files
committed
reference, constant in-class initializer
huihut#79
1 parent 191b305 commit 456ced1

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
* 自身是常量的指针(常量指针,const pointer)
7070
* 引用
7171
* 指向常量的引用(reference to const)
72-
* 没有 const reference,因为引用本身就是 const pointer
72+
* 没有 const reference,因为引用只是对象的别名,引用不是对象,不能用 const 修饰
7373

7474
> (为了方便记忆可以想成)被 const 修饰(在 const 后面)的值不可改变,如下文使用例子中的 `p2``p3`
7575
@@ -82,7 +82,7 @@ const 使用
8282
class A
8383
{
8484
private:
85-
const int a; // 常对象成员,只能在初始化列表赋值
85+
const int a; // 常对象成员,可以使用初始化列表或者类内初始化
8686

8787
public:
8888
// 构造函数

README_en.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ English
7171
* Pointer
7272
* Pointer to const
7373
* A pointer to a constant itself (const pointer)
74-
* Quote
74+
* Reference
7575
* 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
7777

7878
> (Think of it for convenience) The value modified by const (after const) cannot be changed, such as `p2`, `p3` in the usage example below
7979
@@ -87,7 +87,7 @@ const use
8787
class A
8888
{
8989
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
9191

9292
public:
9393
// Constructor

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
* 自身是常量的指针(常量指针,const pointer)
6363
* 引用
6464
* 指向常量的引用(reference to const)
65-
* 没有 const reference,因为引用本身就是 const pointer
65+
* 没有 const reference,因为引用只是对象的别名,引用不是对象,不能用 const 修饰
6666

6767
> (为了方便记忆可以想成)被 const 修饰(在 const 后面)的值不可改变,如下文使用例子中的 `p2``p3`
6868
@@ -75,7 +75,7 @@ const 使用
7575
class A
7676
{
7777
private:
78-
const int a; // 常对象成员,只能在初始化列表赋值
78+
const int a; // 常对象成员,可以使用初始化列表或者类内初始化
7979

8080
public:
8181
// 构造函数

docs/en.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
* Pointer
6565
* Pointer to const
6666
* A pointer to a constant itself (const pointer)
67-
* Quote
67+
* Reference
6868
* 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
7070

7171
> (Think of it for convenience) The value modified by const (after const) cannot be changed, such as `p2`, `p3` in the usage example below
7272
@@ -80,7 +80,7 @@ const use
8080
class A
8181
{
8282
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
8484

8585
public:
8686
// Constructor
@@ -95,7 +95,7 @@ public:
9595
void function()
9696
{
9797
// 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
9999
const A a; // constant object, can only call constant member functions
100100
const A *p = &a; // pointer variable, point to a constant object
101101
const A &q = a; // reference to constant object

0 commit comments

Comments
 (0)