Skip to main content

mutable VS const

Posted in

class A {
  mutable int value1;
 
  public:
     int getValue1() const;
};
 
...
 
int A::getValue1() const
{
  return ++vaue1;
}

No problem since keyword "mutable" allows class member modification despite "const" limitation.

Making some data member mutable is not a crime. It is usually used for caching some values. But... If most of data members are supposed to be mutable, then it is a good practice to put them in a separate class.

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
 `OooOOo.          o       O  OooOOo.    o              
o `o O o O `O O
O O `o O' o O o
o .O O o O .o o
OOooOO' .oOo. `O' oOooOO' O 'OoOo.
o o OooO' o o O o O
O O O O O o . O o
O o `OoO' O o' OOoOooO o O

Enter the code depicted in ASCII art style.