1 2 3 4 5 6 7 8 9 10 11
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Constness</title><meta name="generator" content="DocBook XSL Stylesheets V1.64.1"><link rel="home" href="index.html" title="Programming with gtkmm2"><link rel="up" href="apa.html" title="AppendixA.The RefPtr smartpointer"><link rel="previous" href="apas04.html" title="Checking for null"><link rel="next" href="apb.html" title="AppendixB.Signals"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Constness</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apas04.html">Prev</a></td><th width="60%" align="center">AppendixA.The RefPtr smartpointer</th><td width="20%" align="right"><a accesskey="n" href="apb.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2520635"></a>Constness</h2></div></div><div></div></div><p>The use of the const keyword in C++ is not always clear. You
might not realise that <tt class="literal">const Something*</tt> declares a
pointer to a const Something, The pointer can be changed, but not the
Something that it points to.</p><p>Therefore, the RefPtr equivalent of
<tt class="literal">Something*</tt> for a method parameter is <tt class="literal">const
Glib::RefPtr<Something>&</tt>, and the equivalent of
<tt class="literal">const Something*</tt> is <tt class="literal">const Glib::RefPtr<const
Something>&</tt>.</p><p>The <tt class="literal">const ... &</tt> around
both is just for efficiency, like using <tt class="literal">const std::string&</tt>
instead of <tt class="literal">std::string</tt> for a method parameter to
avoid unnecessary copying.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="apas04.html">Prev</a></td><td width="20%" align="center"><a accesskey="u" href="apa.html">Up</a></td><td width="40%" align="right"><a accesskey="n" href="apb.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Checking for null</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">AppendixB.Signals</td></tr></table></div></body></html>
|