Sophie

Sophie

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

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

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Casting</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="chapter-refptr.html" title="Appendix A. The RefPtr smartpointer">
<link rel="prev" href="sec-refptr-dereferencing.html" title="Dereferencing">
<link rel="next" href="sec-refptr-checking-for-null.html" title="Checking for null">
</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">Casting</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="sec-refptr-dereferencing.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center">Appendix A. The RefPtr smartpointer</th>
<td width="20%" align="right"> <a accesskey="n" href="sec-refptr-checking-for-null.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="Casting">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-refptr-casting"></a>Casting</h2></div></div></div>
<p>
You can cast <code class="classname">RefPtrs</code> to base types, just like normal
pointers.
</p>
<p>
</p>
<pre class="programlisting">
Glib::RefPtr&lt;Gtk::TreeStore&gt; refStore = Gtk::TreeStore::create(columns);
Glib::RefPtr&lt;Gtk::TreeModel&gt; refModel = refStore;
</pre>
<p>
</p>
<p>This means that any method which takes a <span class="type">const
Glib::RefPtr&lt;BaseType&gt;</span> argument can also take a
<span class="type">const Glib::RefPtr&lt;DerivedType&gt;</span>. The cast is
implicit, just as it would be for a normal pointer.</p>
<p>You can also cast to a derived type, but the syntax is
a little different than with a normal pointer.
</p>
<p>
</p>
<pre class="programlisting">
Glib::RefPtr&lt;Gtk::TreeStore&gt; refStore =
Glib::RefPtr&lt;Gtk::TreeStore&gt;::cast_dynamic(refModel);
Glib::RefPtr&lt;Gtk::TreeStore&gt; refStore2 =
Glib::RefPtr&lt;Gtk::TreeStore&gt;::cast_static(refModel);
</pre>
<p>
</p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="sec-refptr-dereferencing.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"><a accesskey="u" href="chapter-refptr.html"><img src="icons/up.png" alt="Up"></a></td>
<td width="40%" align="right"> <a accesskey="n" href="sec-refptr-checking-for-null.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Dereferencing </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"> Checking for null</td>
</tr>
</table>
</div>
</body>
</html>