include
using namespace std;
#include
class person {
public:
//this指针的本质是指针常量,指针的指向是不可以修改的
//在成员函数后面加const,修饰的是this的指向,让指针指向的值也不可以修改
void showperson() const{//常函数
m_B = 100;
//m_A = 100;//不可修改
//this->m_A = 100;//在成员函数后面加const,this指针指向的值也不可以修改
//this = NULL;//this指针不可以修改指向
}
void func(){}
int m_A;
mutable int m_B;//特殊变量,即使在常函数中也可以修改这个值 加关键字mutable
};
//常对象
void test02() {
const person p;//在对象前加const变为常对象
//p.m_A = 100;//不可修改
p.m_B = 100;//m_B是特殊值,在常对象下也可以修改。
p.showperson();
//p.func();//常对象只能调用常函数
}

void test() {
person p;
p.showperson();
}
int main() {
test();
return 0;
}