Sophie

Sophie

distrib > * > 2010.0 > * > by-pkgid > 345aa895e80053137c21f8693106c3a0 > files > 34

gtkmm2.4-documentation-2.17.4-1mdv2010.0.noarch.rpm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Appendix A. The RefPtr smartpointer</title>
<link rel="stylesheet" href="style.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.1">
<link rel="home" href="index.html" title="Programming with gtkmm">
<link rel="up" href="index.html" title="Programming with gtkmm">
<link rel="prev" href="chapter-contributing.html" title="Chapter 27. Contributing">
<link rel="next" href="sec-refptr-dereferencing.html" title="Dereferencing">
</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">Appendix A. The RefPtr smartpointer</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="chapter-contributing.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center"> </th>
<td width="20%" align="right"> <a accesskey="n" href="sec-refptr-dereferencing.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="appendix" title="Appendix A. The RefPtr smartpointer">
<div class="titlepage"><div><div><h2 class="title">
<a name="chapter-refptr"></a>Appendix A. The RefPtr smartpointer</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<ul>
<li><span class="sect1"><a href="chapter-refptr.html#sec-refptr-copying">Copying</a></span></li>
<li><span class="sect1"><a href="sec-refptr-dereferencing.html">Dereferencing</a></span></li>
<li><span class="sect1"><a href="sec-refptr-casting.html">Casting</a></span></li>
<li><span class="sect1"><a href="sec-refptr-checking-for-null.html">Checking for null</a></span></li>
<li><span class="sect1"><a href="sec-refptr-constness.html">Constness</a></span></li>
</ul>
</div>
<p>
<code class="classname">Glib::RefPtr</code> is a smartpointer. Specifically, it is a
reference-counting smartpointer. You might be familiar with
<code class="literal">std::auto_ptr&lt;&gt;</code>, which is also a smartpointer, but
<code class="literal">Glib::RefPtr&lt;&gt;</code> is much simpler, and more useful. We
expect a future version of the C++ Standard Library to contain a
reference-counting shared smartpointer, and a future version of <span class="application">gtkmm</span> might possibly use that instead.</p>
<p><a class="ulink" href="http://library.gnome.org/devel/glibmm/unstable/classGlib_1_1RefPtr.html" target="_top">Reference</a></p>
<p>A smartpointer acts much like a normal pointer. Here are a few examples.</p>
<div class="sect1" title="Copying">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-refptr-copying"></a>Copying</h2></div></div></div>
<p>
You can copy <code class="classname">RefPtr</code>s, just like normal pointers. But
unlike normal pointers, you don't need to worry about deleting the underlying
instance.
</p>
<p>
</p>
<pre class="programlisting">
Glib::RefPtr&lt;Gdk::Bitmap&gt; refBitmap = Gdk::Bitmap::create(window,
data, width, height);
Glib::RefPtr&lt;Gdk::Bitmap&gt; refBitmap2 = refBitmap;
</pre>
<p>
</p>
<p>
Of course this means that you can store <code class="classname">RefPtrs</code> in
standard containers, such as <code class="classname">std::vector</code> or
<code class="classname">std::list</code>.</p>
<p>
</p>
<pre class="programlisting">
std::list&lt; Glib::RefPtr&lt;Gdk::Pixmap&gt; &gt; listPixmaps;
Glib::RefPtr&lt;Gdk::Pixmap&gt; refPixmap = Gdk::Pixmap::create(window,
width, height, depth);
listPixmaps.push_back(refPixmap);
</pre>
<p>
</p>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="chapter-contributing.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"> </td>
<td width="40%" align="right"> <a accesskey="n" href="sec-refptr-dereferencing.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Chapter 27. Contributing </td>
<td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td>
<td width="40%" align="right" valign="top"> Dereferencing</td>
</tr>
</table>
</div>
</body>
</html>