Symbian3/SDK/Source/GUID-0C8389B8-91DF-58A1-A2A1-945A18CCBB10.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Tue, 20 Jul 2010 12:00:49 +0100
changeset 13 48780e181b38
parent 0 89d6a7a84779
permissions -rw-r--r--
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-0C8389B8-91DF-58A1-A2A1-945A18CCBB10" xml:lang="en"><title>Using
TLitC operators</title><shortdesc>Explains how to use <codeph>TLitC</codeph> operations.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
<p>The <codeph>TLitC</codeph> class offers four operators, two of which are
conversion operators.</p>
<p>The conversion operators are invoked by the compiler when a <codeph>TLitC&lt;TInt&gt;</codeph> type
is passed to a function which takes the following argument types:</p>
<ul>
<li id="GUID-BEF085A9-56B5-579F-A316-B68C108BED9B"><p>a reference by value,
i.e. a <codeph>TRefByValue&lt;class              T&gt;</codeph> type</p> </li>
<li id="GUID-911E904A-83F8-52B1-BAA1-0C993683BAD3"><p>a const reference to
a descriptor, i.e. a <codeph>const              TDesC&amp;</codeph> type</p> </li>
</ul>
<p>The other two operators return:</p>
<ul>
<li id="GUID-B42C7636-5E8F-5BD6-98C8-1EF0E7AD388D"><p>a pointer to a constant
descriptor, i.e. a <codeph>const              TDesC*</codeph> type</p> </li>
<li id="GUID-141D07F5-4D60-5940-A404-2718494D6CCB"><p>a reference to a constant
descriptor, i.e. a <codeph>const              TDesC&amp;</codeph> type</p> </li>
</ul>
<p>The following code fragments show the situations where the operators are
called on a <codeph>TLitC</codeph>. The fragments are similar for both <codeph>TLitC8</codeph> and <codeph>TLitC16</codeph>.</p>
<section id="GUID-AF4A4619-1C5A-4022-9700-4EB09C9001FE"><title>Reference by value conversion operator operator const __TRefDesC()</title> <p>The
following code fragment shows the operator in use:</p> <codeblock id="GUID-63CE5630-61CB-5428-8F7C-EB84445FD63A" xml:space="preserve">...
TBuf&lt;256&gt; x;
...
_LIT(KTxtFormat,"There are %d cm in a metre");
x.Format(KTxtFormat,100);
...
</codeblock> </section>
<section id="GUID-6B904805-4C60-4721-B02D-6999CA18E2F5"><title>Const descriptor reference conversion operator operator const
TDesC&amp;</title> <p>The following code fragment shows the operator in use:</p> <codeblock id="GUID-8D7F387D-B675-5EC4-B88D-4389F4D5B961" xml:space="preserve">...
_LIT(KSomeData,"Some data");
...
TPtrC x(KSomeData);</codeblock> </section>
<section id="GUID-6389D8D4-CC0E-45AA-81EC-43E86C28A7AE"><title>Address of operator operator&amp;()</title> <p>The following
code fragment shows the operator in use:</p> <codeblock id="GUID-1AE87D87-53AD-5E88-864A-785D95598D02" xml:space="preserve">class CX...
 {
 void Foo(const TDesC* aDesC);
 };

...
_LIT(KLiteral,"some text");
...
CX* anx;
...
anx-&gt;Foo(&amp;KLiteral);
...</codeblock> </section>
<section id="GUID-52E52945-1FFD-4B49-96C0-2D423B829033"><title>Reference operator operator()</title> <p>The following code
fragment shows the operator in use:</p> <codeblock id="GUID-2A7C5828-7C2B-58F2-819E-9EAAD6071457" xml:space="preserve">...
_LIT(KKeywordSelect,"select");
if (KKeywordSelect().CompareF(token)&lt;0)
...</codeblock> </section>
</conbody></concept>