Pergunta de entrevista da empresa Bloomberg

What is the (C++) keyword mutable used for? Give an example.

Resposta da entrevista

Sigiloso

27 de jun. de 2010

Mutable is used to specify a variable that can be changed even if it is declared as const. For e.g class MyClass { public: mutable int x; }; int main() { const MyClass o; o.x = 10; //Can change the value of x as it is mutable. };