What if you wanted to have a const member function which did an expensive calculation and returned the result?
It would be nice to be able to cache this result and avoid recalculation for subsequent calls to the function.
But since it’s a const member function, you can’t store the cached result inside the class, because to do so, you’d have to modify a member variable (thereby violating const).
The mutable storage specifier was added for this reason. A mutable member variable can be modified even by const member functions.
Resolving technical problems:
Solve your technical problems instantly
We provide Remote Technical Support from Monday to Sunday, 7:00PM to 1:00 AM
Mail your problem details at email@example.com along with your mobile numberand we will give you a call for further details. We usually attend your problems within 60 minutes and solve it in maximum 2 days.