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 a constant reference?

1 Answers  


What is the difference between passing by reference and passing a reference?

1 Answers  


Explain unexpected() function?

1 Answers  


Which software is used for c++ programming?

1 Answers  


What is the hardest coding language to learn?

1 Answers  


What is c++ redistributable?

1 Answers  


What does floor mean in c++?

1 Answers  


Is it legal in c++ to overload operator++ so that it decrements a value in your class?

1 Answers  


If a header file is included twice by mistake in the program, will it give any error?

1 Answers  


What's the order in which the objects in an array are destructed?

1 Answers  


Write a corrected statement in c++ so that the statement will work properly. if (x = y) x = 2*z;

2 Answers  


how to access grid view row?

1 Answers  


Categories