C++ examples for Class:Member Field
Mutable Class Members, storage-class specifier mutable.
#include <iostream> using namespace std; class TestMutable { public: /*from w ww . j av a2 s.c om*/ TestMutable( int v = 0 ) { value = v; } int getValue() const { return ++value; // increments value } private: mutable int value; // mutable member }; int main() { const TestMutable test( 99 ); cout << "Initial value: " << test.getValue(); cout << "\nModified value: " << test.getValue() << endl; }