1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Casting</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="apas02.html" title="Dereferencing"><link rel="next" href="apas04.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="apas02.html">Prev</a></td><th width="60%" align="center">AppendixA.The RefPtr smartpointer</th><td width="20%" align="right"><a accesskey="n" href="apas04.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="id2520549"></a>Casting</h2></div></div><div></div></div><p>You can cast RefPtrs to base types, just like normal pointers.</p><p>
</p><pre class="programlisting">
Glib::RefPtr<Gtk::TreeStore> refStore = Gdk::TreeStore::create(columns);
Glib::RefPtr<Gtk::TreeModel> refModel = refStore;
</pre><p>
</p><p>This means that any method which takes a <tt class="literal">const
Glib::RefPtr<BaseType></tt> argument can also take a
<tt class="literal">const Glib::RefPtr<DerivedType></tt>. 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<Gtk::TreeStore> refStore =
Glib::RefPtr<Gtk::TreeStore>::cast_dynamic(refModel);
Glib::RefPtr<Gtk::TreeStore> refStore2 =
Glib::RefPtr<Gtk::TreeStore>::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="apas02.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="apas04.html">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">Home</a></td><td width="40%" align="right" valign="top">Checking for null</td></tr></table></div></body></html>
|