1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>AppendixA.The RefPtr smartpointer</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="index.html" title="Programming with gtkmm2"><link rel="previous" href="ch22.html" title="Chapter22.Contributing "><link rel="next" href="apas02.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">AppendixA.The RefPtr smartpointer</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch22.html">Prev</a></td><th width="60%" align="center"></th><td width="20%" align="right"><a accesskey="n" href="apas02.html">Next</a></td></tr></table><hr></div><div class="appendix" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="sec-appendix-refptr"></a>AppendixA.The RefPtr smartpointer</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="apa.html#id2520456">Copying</a></span></dt><dt><span class="sect1"><a href="apas02.html">Dereferencing</a></span></dt><dt><span class="sect1"><a href="apas03.html">Casting</a></span></dt><dt><span class="sect1"><a href="apas04.html">Checking for null</a></span></dt><dt><span class="sect1"><a href="apas05.html">Constness</a></span></dt></dl></div><p>
Glib::RefPtr is a smartpointer. Specifically, it is a
reference-counting smartpointer. You might be familiar with
<tt class="literal">std::auto_ptr<></tt>, which is also a smartpointer, but <tt class="literal">Glib::RefPtr<></tt> is
much simpler, and more useful. We expect a future version of the
C++ Standard Library to contain a reference-counting shared
smartpointer, so a future version of gtkmm will probably use that
instead.</p><p><a href="../../reference/html/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" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2520456"></a>Copying</h2></div></div><div></div></div><p>You can copy RefPtrs, 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<Gdk::Bitmap> refBitmap = Gdk::Bitmap::create(window,
data, width, height);
Glib::RefPtr<Gdk::Bitmap> refBitmap2 = refBitmap;
</pre><p>
</p><p>Of course this means that you can store RefPtrs in standard
containers, such as std::vector or std::list.</p><p>
</p><pre class="programlisting">
std::list< Glib::RefPtr<Gdk::Pixmap> > listPixmaps;
Glib::RefPtr<Gdk::Pixmap> 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="ch22.html">Prev</a></td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"><a accesskey="n" href="apas02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter22.Contributing </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">Dereferencing</td></tr></table></div></body></html>
|