Is it possible, without using the mutable keyword for the m_nValue member variable of the CBase class, to change its value inside the constant function Test?
class CBase
{
public:

   CBase() { m_nValue = 0; }
   void Test() const;

private:

   int m_nValue;    
};
Explanation
Technically, there is such an opportunity. BUT! This is not recommended, as the class user, looking at the class interface, does not expect such actions from void CBase::Test() const. This is essentially a cheat.
void CBase::Test() const 
{
   const_cast< CBase * >( this )->m_nValue--;
}

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes