mirror of
https://github.com/huihut/interview.git
synced 2024-03-22 13:10:48 +08:00
constant members cannot be updated
https://github.com/huihut/interview/issues/78 https://github.com/huihut/interview/issues/77
This commit is contained in:
parent
e6dbc2b9c3
commit
191b30533e
|
@ -97,7 +97,7 @@ public:
|
||||||
void function()
|
void function()
|
||||||
{
|
{
|
||||||
// 对象
|
// 对象
|
||||||
A b; // 普通对象,可以调用全部成员函数、更新常成员变量
|
A b; // 普通对象,可以调用全部成员函数
|
||||||
const A a; // 常对象,只能调用常成员函数
|
const A a; // 常对象,只能调用常成员函数
|
||||||
const A *p = &a; // 指针变量,指向常对象
|
const A *p = &a; // 指针变量,指向常对象
|
||||||
const A &q = a; // 指向常对象的引用
|
const A &q = a; // 指向常对象的引用
|
||||||
|
|
|
@ -102,7 +102,7 @@ public:
|
||||||
void function()
|
void function()
|
||||||
{
|
{
|
||||||
// object
|
// 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 a; // constant object, can only call constant member functions
|
||||||
const A *p = &a; // pointer variable, point to a constant object
|
const A *p = &a; // pointer variable, point to a constant object
|
||||||
const A &q = a; // reference to constant object
|
const A &q = a; // reference to constant object
|
||||||
|
|
|
@ -90,7 +90,7 @@ public:
|
||||||
void function()
|
void function()
|
||||||
{
|
{
|
||||||
// 对象
|
// 对象
|
||||||
A b; // 普通对象,可以调用全部成员函数、更新常成员变量
|
A b; // 普通对象,可以调用全部成员函数
|
||||||
const A a; // 常对象,只能调用常成员函数
|
const A a; // 常对象,只能调用常成员函数
|
||||||
const A *p = &a; // 指针变量,指向常对象
|
const A *p = &a; // 指针变量,指向常对象
|
||||||
const A &q = a; // 指向常对象的引用
|
const A &q = a; // 指向常对象的引用
|
||||||
|
|
Loading…
Reference in New Issue
Block a user