File: apas03.html

package info (click to toggle)
gtkmm2.0 2.2.12-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 56,872 kB
  • ctags: 51,600
  • sloc: xml: 73,173; cpp: 20,565; sh: 8,608; perl: 2,702; makefile: 1,233
file content (18 lines) | stat: -rw-r--r-- 2,526 bytes parent folder | download | duplicates (2)
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&lt;Gtk::TreeStore&gt; refStore = Gdk::TreeStore::create(columns);
Glib::RefPtr&lt;Gtk::TreeModel&gt; refModel = refStore;
</pre><p>
</p><p>This means that any method which takes a <tt class="literal">const
Glib::RefPtr&lt;BaseType&gt;</tt> argument can also take a
<tt class="literal">const Glib::RefPtr&lt;DerivedType&gt;</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&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="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>