提交 456ced1e 编写于 作者: 辉哈's avatar 辉哈

reference, constant in-class initializer

https://github.com/huihut/interview/issues/79
上级 191b3053
......@@ -69,7 +69,7 @@
* 自身是常量的指针(常量指针,const pointer)
* 引用
* 指向常量的引用(reference to const)
* 没有 const reference,因为引用本身就是 const pointer
* 没有 const reference,因为引用只是对象的别名,引用不是对象,不能用 const 修饰
> (为了方便记忆可以想成)被 const 修饰(在 const 后面)的值不可改变,如下文使用例子中的 `p2`、`p3`
......@@ -82,7 +82,7 @@ const 使用
class A
{
private:
const int a; // 常对象成员,只能在初始化列表赋值
const int a; // 常对象成员,可以使用初始化列表或者类内初始化
public:
// 构造函数
......
......@@ -71,9 +71,9 @@ English
* Pointer
* Pointer to const
* A pointer to a constant itself (const pointer)
* Quote
* Reference
* Reference to const
* There is no const reference because the reference itself is a const pointer
* There is no const reference because the reference is an alias of an object, the reference is not an object
> (Think of it for convenience) The value modified by const (after const) cannot be changed, such as `p2`, `p3` in the usage example below
......@@ -87,7 +87,7 @@ const use
class A
{
private:
const int a; // constant object member, can only be assigned in the initialization list
const int a; // constant object member, can use initialization list or in-class initializer
public:
// Constructor
......
......@@ -62,7 +62,7 @@
* 自身是常量的指针(常量指针,const pointer)
* 引用
* 指向常量的引用(reference to const)
* 没有 const reference,因为引用本身就是 const pointer
* 没有 const reference,因为引用只是对象的别名,引用不是对象,不能用 const 修饰
> (为了方便记忆可以想成)被 const 修饰(在 const 后面)的值不可改变,如下文使用例子中的 `p2`、`p3`
......@@ -75,7 +75,7 @@ const 使用
class A
{
private:
const int a; // 常对象成员,只能在初始化列表赋值
const int a; // 常对象成员,可以使用初始化列表或者类内初始化
public:
// 构造函数
......
......@@ -64,9 +64,9 @@
* Pointer
* Pointer to const
* A pointer to a constant itself (const pointer)
* Quote
* Reference
* Reference to const
* There is no const reference because the reference itself is a const pointer
* There is no const reference because the reference is an alias of an object, the reference is not an object
> (Think of it for convenience) The value modified by const (after const) cannot be changed, such as `p2`, `p3` in the usage example below
......@@ -80,7 +80,7 @@ const use
class A
{
private:
const int a; // constant object member, can only be assigned in the initialization list
const int a; // constant object member, can use initialization list or in-class initializer
public:
// Constructor
......@@ -95,7 +95,7 @@ public:
void function()
{
// object
A b; // ordinary object, can call all member functions, update constant member variables
A b; // ordinary object, can call all member functions
const A a; // constant object, can only call constant member functions
const A *p = &a; // pointer variable, point to a constant object
const A &q = a; // reference to constant object
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册