Demonstrating storage-class specifier mutable : mutable « Language Basics « C++ Tutorial






#include <iostream>
using std::cout;
using std::endl;

class MyClass {
public:
   MyClass( int v )
   {
      value = v;
   }

   int getValue() const
   {
      return value++;
   }
private:
   mutable int value;
};

int main()
{
   const MyClass test( 99 );

   cout << "Initial value: " << test.getValue();
   cout << "\nModified value: " << test.getValue() << endl;
   return 0;
}
Initial value: 99
Modified value: 100








1.14.mutable
1.14.1.Demonstrate mutable.
1.14.2.Demonstrating storage-class specifier mutable