Mutable
(1) mutable means "variable, variable", which is the opposite of const in C ++.
(2) In C ++, mutable is also set to break through the const restrictions. Variables modified by mutable will always be in a mutable state, even in a const Function
Instance description:
# include
using
namespace STD;
class tew.utable
{< br>
Public :< br> tew.utable () {I =
0 ;}< br>
int output ()
const
{< br>
return I ++;
//
error c2166: l-value specifies const object
}< br>
private :
int I;
};
int main ()
{< br> tew.utable;
cout
return
0 ;< BR >}
Obviously, I ++ cannot compile the const modifier function.
# Include <iostream>
Using NamespaceSTD;
ClassTestmutable
{
Public:
Testmutable () {I =0;}
IntOutput ()Const
{
ReturnI ++;
}
Private:
MutableIntI;
};
IntMain ()
{
Testmutable;
Cout <testmutable. Output () <Endl;
Return 0;
}
After mutable is added to int I, the compilation is passed, and the function of the keyword mutable can be seen immediately.