The mutable keyword can only be applied to non-static and non-const data members of a class. If a data member is declared mutable then it is legal to assign a value to this data member from a const member function.
SEE FOLLOWING CODE :-
********************************************
class Mutable
{
private :
int m_iNonMutVar;
mutable int m_iMutVar;
public:
Mutable();
void TryChange() const;
};
Mutable::Mutable():m_iNonMutVar(10) m_iMutVar(20) {};
void Mutable::TryChange() const
{
m_iNonMutVar 100; // THis will give ERROR
m_iMutVar 200; // This will WORK coz it is mutable
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment