//第二十五章补充内容 11 关键字mutable
//我们知道修饰为const的成员函数,是不能修改类的数据成员的,但是这并不表示它不可以修改经过mutable修饰后的数据成员,关键字mutable将其后的数据修饰为可供const成员函数进行修改的数据成员
/*#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class A
{
public:
A(int i):x(i){}
int add()const //注意这里是const
{
return ++x;
}
void show()const{
cout<<"x:"<<x<<endl;
}
private:
mutable int x; //你可以试着将这里的去掉试试nutable
};
int main()
{
//A a(10);
//a.add();
//a.show();
A a(0);
for(int tmp, i=0; i<10; i++)
{
tmp = a.add();
cout<<setw(tmp)<<setfill(' ')<<tmp<<endl;
}
return 0;
}*/