const常函数:
在函数后面加const表示不能修改 this 所指向的值
(特殊:通过 multable 对特殊成员变量进行修饰,可以进行修改)
#include<iostream>
#include<cstdio>
using namespace std;
class T{
public:
int a;
mutable int b;
public:
// 相当于 const 修饰了 this 指针
void func() const{
b = 10;
// a = 10; 不允许修改 this 所指向的内容
}
};
int main()
{
T t = T();
t.func();
return 0;
}