answersLogoWhite

0


Best Answer

mutable keyword can only be applied to non-static and non-constant member of a class. It indicates that the corresponding data member can be modified even from the constant function. (Constant function: is a function marked with the keyword const)

For eg.

class x {

private:

mutable int query_count;

int value;

public:

int get_value() const

{

query_count++;

return value;

}

};

In the code above member query_count is marked with keyword mutable. Hence it's value can be modified from constant function get_value().

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

7y ago

Most class accessors need to cater for both constant and non-constant access. If the class representation doesn't change when an accessor method is invoked then this isn't a problem. However, when an accessor needs to modify the class representation we cannot make that accessor constant and therefore cannot call that method on constant objects of the class. To get around that problem, members that need to be modified by an accessor need to be declared mutable.

Typically, mutable data members are only used internally be the class (for housekeeping purposes) and play no part in the logical representation of the class (as viewed by users of the class).

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: In c plus plus what is Mutable keyword?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering
Related questions

What is meant by println in c plus plus?

println is not a C++ keyword.


What is use of keyword extra in c plus plus programming?

Nothing.


Is it possible to declare a keyword as an identifier in c plus plus?

No. Keywords are reserved and cannot be used as identifiers. However, C/C++ is case-sensitive. So although register is a reserved keyword, Register is not.


How does the use of the 'void' keyword differ in C plus plus vs. C?

It doesn't. Void has the same meaning in both.


Is there any keyword in c or c plus plus like the function inkey in qbasic?

Using TurboC? kbhit and getch are your friends


How java use extern key word which is used in C plus plus?

No extern keyword in Java.


Instantiation of objects in c plus plus?

Objects are instantiated when statically declared or dynamically created with the new keyword.


Why you use zero instead of NULL in c plus plus?

In C++ NULL is defined as 0. It's a design failure, will be fixed with a new 'nullptr' keyword.


What is friendly in c plus plus?

The keyword "friend" allows a function or variable to have access to a protected member inside a class.


Is in is used as a keyword in C language?

Neither "in" nor "is" is a keyword in C.


What is meaning of keyword in c language?

'Keyword' is a synonym for 'reserved word', it is not specific to C language.


What is auto in turbo c?

Keyword.