keyword mutable

From Cppwiki

Jump to: navigation, search


The mutable specifier indicates that the member may be modified even in a const member function.

Example:

 class foo {
   mutable int count;
 
 public:
   int IncrementCount() const {
     ++count;
   }
 };

In this example, IncrementCount may be called on a const object. (This is not a particularly good example, IncrementCount would normally be expected to be non-const. A better, and typical, example would be in a threaded synchronization object. Such objects often allow locking even of const instances.)

Personal tools