What is "mutable" keyword?

Answers were Sorted based on User's Feedback



What is "mutable" keyword?..

Answer / roshanpr

mutable key word is used when u want to make any member
variable of a const object modifyable.

Basically when u make a object constant u cannot modify its
data members. But during the declaration of the class if a
data member is declared as mutable it can changed.

Class my
{

mutable int age;

public:

my(){age=0;}
void plusplus(int b)const
{
age+=b;
}
};

int main()
{
const my obj;
obj.plusplus(40);
}

Is This Answer Correct ?    41 Yes 7 No

What is "mutable" keyword?..

Answer / shakti singh khinchi

Mutable keyword is used to modify a data member of an object
which has declared as constant. for example:

class XYZ
{
public:
int i;
mutable int cc;
public:
XYZ();
};

int main()
{
const XYZ obj;
obj.cc = 100; // modify obj object's member "cc" which has
been declared as mutable.
}

Is This Answer Correct ?    16 Yes 7 No

Post New Answer

More C++ General Interview Questions

what is COPY CONSTRUCTOR and what is it used for?

0 Answers  


which is the easy way to divide any integer by 2?

2 Answers   Persistent,


How many static variables are created if you put one static member into a template class definition?

0 Answers  


What happens when the extern "c" char func (char*,waste) executes?

0 Answers  


how many controls can we place on single form.

1 Answers   Microsoft,






Do the names of parameters have to agree in the prototype, definition, and call to the function?

0 Answers  


What compiler was used?

6 Answers   Intel,


What are mutator methods in c++?

0 Answers  


What is constant in c++ with example?

0 Answers  


What is polymorphism in c++? Explain with an example?

0 Answers  


The "virtual" specifier in a member function enables which one of the following? a) Monmorphism b) Late binding c) Metamorphism d) Solomorphism e) Inheritance

4 Answers   Quark,


Is c++ the hardest language?

0 Answers  


Categories