C++:mutable关键字

mutable 关键字 虽然很少看到 , 但其功能也是比较重要的 , 用mutable关键字修饰的变量  在程序的任何位置 都处于可变状态。

就算是在 const 函数中  其值也能被改变

例:

  

 1 class      Test
 2 {
 3 public:
 4                 Test(){a = 0;}
 5 public:
 6     mutable    int    a;
 7     void    func () const{
 8         a = 1000;
 9     }
10 };
11 int main(int argc, char* argv[])
12 {
13     Test    b;
14     b.func();
15     cout<<b.a<<endl;
16     return 0;
17 }
18 
19 //// 运行后会输出 1000
原文地址:https://www.cnblogs.com/wowk/p/3127060.html