[] [c++]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<bits/stdc++.h>
using namespace std;

class Person
{
public:
//this指针的本质是指针常量 指向是不可以修改的
//在成员函数后面加const 修饰的是this指向 让指针指向的值也不可以修改
void showPerson() const
{
this->m_B=100;//特殊
//this->m_A=100; 不可修改
//this=NULL; 不可修改
}
int m_A;
mutable int m_B;//特殊变量 即使在常函数中也可以修改
};
void test02()
{
const Person p1;//常对象
//p.m_A=100; 报错 不可以修改
p1.m_B=100;

//常对象只能调用常函数
p1.showPerson();

}
int main()
{

}