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 protected inheritance?

0 Answers  


write a program in c++ to generate imp z y x w v w x y z z y x w x y z z y x y z z y z z

4 Answers  


How the virtual functions maintain the call up?

0 Answers  


what is data encapsulation in C++?

0 Answers  


What is #include math h in c++?

0 Answers  






What is object oriented programming (oop)?

0 Answers  


What are c++ data types?

0 Answers  


What are the data types in c++?

0 Answers  


Is c++ low level?

0 Answers  


What is the Difference between "C structure" and "C++ structure"?

12 Answers  


How will you call C functions from C ++ and vice-versa?

0 Answers   Agilent, Tavant Technologies, Thomson Reuters, Verifone,


What is the full form of ios?

0 Answers  


Categories