equal
deleted
inserted
replaced
|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept id="GUID-1D9376CD-3160-5CD8-A138-B94C5F7A50F8" xml:lang="en"><title>Using |
|
13 MUTABLE_CAST macro</title><shortdesc>This topic explains how to cast away the constant of the counter |
|
14 variable.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
15 <p>In the example code below, the class has a simple const getter function <codeph>Var()</codeph>. |
|
16 It uses <codeph>MUTABLE_CAST</codeph> to cast away the <codeph>const</codeph> -ness |
|
17 of the counter variable <codeph>iGetCounter</codeph>, which allows that variable |
|
18 to be changed.</p> |
|
19 <codeblock id="GUID-8EA00511-AA50-5401-B13D-D21C4611B22F" xml:space="preserve">class TMutableDemo |
|
20 { |
|
21 public: |
|
22 TMutableDemo(TUint a=0):iVar(a),iGetCounter(0) {}; |
|
23 TUint Var() const; |
|
24 |
|
25 private: |
|
26 TUint iVar; |
|
27 __MUTABLE TUint iGetCounter; |
|
28 }; |
|
29 |
|
30 TUint TMutableDemo::Var() const |
|
31 { |
|
32 MUTABLE_CAST(TMutableDemo*,this)->iGetCounter++; |
|
33 return iVar; |
|
34 }</codeblock> |
|
35 </conbody></concept> |