What is "mutable" keyword?
Answers were Sorted based on User's Feedback
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 |
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 |
what are Access specifiers in C++ class? What are the types?
What are static member functions?
Do vectors start at 0 c++?
What is the outcome of cout< a) 16 b) 17 c) 16.5
What is meaning of in c++?
What is the importance of mutable keyword?
Incase of a function declaration, what is extern means?
Why do we use classes in programming?
write a program to add two numbers without using an arithmetic operator.
What is object in c++ example?
What operator is used to access a struct through a pointer a) >> b) -> c) *
How long it will take to learn c++?