Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



Using MUTABLE_CAST macro

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;
 }