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

Write a recursive program to calculate factorial in c++.

0 Answers  


Should you pass exceptions by value or by reference?

0 Answers  


How can you quickly find the number of elements stored in a dynamic array? Why is it difficult to store linked list in an array?

0 Answers  


what are prototypes

4 Answers   Infosys, TCS,


What is ios class in c++?

0 Answers  






Differentiate between an external iterator and an internal iterator? What is the advantage of an external iterator.

0 Answers  


What do you mean by late binding?

0 Answers  


What is the difference between an array and a list?

0 Answers  


Can I make ios apps with c++?

0 Answers  


CAN U SAY WHICH PROGRAMING LANGUAGE IS USED BY DOCTORS....?

1 Answers  


What is the use of dot in c++?

0 Answers  


Differentiate between an array and a list?

0 Answers  


Categories