This topic explains how to cast away the constant of the counter variable.
In the example code below, the class has a simple const getter function Var() . It uses MUTABLE_CAST to cast away the const -ness of the counter variable iGetCounter , which allows that variable to be changed.
class TMutableDemo
{
public:
TMutableDemo(TUint a=0):iVar(a),iGetCounter(0) {};
TUint Var() const;
private:
TUint iVar;
__MUTABLE TUint iGetCounter;
};
TUint TMutableDemo::Var() const
{
MUTABLE_CAST(TMutableDemo*,this)->iGetCounter++;
return iVar;
}
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.