fig21_12.cpp

来自「经典vc教程的例子程序」· C++ 代码 · 共 25 行

CPP
25
字号
// Fig. 21.12: fig21_12.cpp
// Demonstrating storage class specifier mutable.
#include <iostream.h>

class TestMutable {
public:
   TestMutable( int v = 0 ) { value = v; }
   void modifyValue() const { value++; }
   int getValue() const { return value; }
private:
   mutable int value;
};

int main()
{
   const TestMutable t( 99 );
   
   cout << "Initial value: " << t.getValue();

   t.modifyValue();   // modifies mutable member
   cout << "\nModified value: " << t.getValue() << endl;

   return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?