#include<iostream>
using namespace std;
//const修饰成员函数
//1.常函数
class person
{
public:
//this指针的本质 是指针常量 指针的指向不可以修改
//person*const this;
//在成员函数后面加const,修饰的是this指针,让指针指向的值也不可以修改
void showPerson()const//加const后值也不能改
{
// m_a=100;
//this指针是不可以修改指针的指向的
m_b=100;
}
int m_a;
mutable int m_b;//特殊变量,即使在常函数中也可以修改这个值
};
void test02()
{
const person p1;//在对象前加const,变为常对象
p1.m_b=100; //特殊值,在常对象下也可以修改
//常对象只能调用常函数
p1.showPerson();
}
为什么test02函数在const person p1的时候会报错啊