class Person
{
public:
//
Person(string name,int age) :m_Name(name), m_Age(age){};
void show();
void show1()const;
private:
mutable string m_Name; //mutable 可消除const成员函数不可修改成员变量的约束
int m_Age;
};
1.this指针的本质
this 指针的本质是常量指针 ;类型名 * const this (例如 Person * const this) ;所以this的指向是不能改变的。下图中修改指向报错
2.const修饰成员函数
const 修饰成员函数,实际上 <=> const 类型名 * const this (例如 const Person *const this) 既不能修改this指向,也不能修改指向的内容。
3.mutable接触const成员函数的不能修改成员变量的限制