What are Mutable and Const in C++ ?

 
 

Class member functions may be declared as const, which causes them to be treated as a const pointer. Thus, that function cannot modify the object that invokes it. Also, a const object may not invoke a non-const member function. However, a const member function can be called by either const or non-const objects. Sometimes there will be one or more members of a class that you want a const function to be able to modify even though you don't want the function to be able to modify any of its other members. You can accomplish this through the use of mutable. It overrides constness. That is, a mutable member can be modified by a const member function. E.g. class MyClass{ int i; mutable int j; Public: void setValues const () { i = 10; //wrong j = 15; //correct }};