File: ch04s02.html

package info (click to toggle)
libsigc%2B%2B-2.0 2.0.10-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 20,220 kB
  • ctags: 6,376
  • sloc: sh: 8,402; cpp: 1,717; xml: 368; makefile: 364; perl: 51; ansic: 45
file content (12 lines) | stat: -rw-r--r-- 2,524 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Retyping</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="LibSigC++"><link rel="up" href="ch04.html" title="Chapter4.Advanced topics"><link rel="previous" href="ch04.html" title="Chapter4.Advanced topics"><link rel="next" href="ch04s03.html" title="Marshallers"></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">Retyping</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch04.html">Prev</a></td><th width="60%" align="center">Chapter4.Advanced topics</th><td width="20%" align="right"><a accesskey="n" href="ch04s03.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="id2491672"></a>Retyping</h2></div></div><div></div></div><p>A similar topic is retyping. Perhaps you have a signal that takes an <tt class="literal">int</tt>, but
	you want to connect a function that takes a <tt class="literal">double</tt>.</p><p>This can be achieved with the <tt class="literal">sigc::retype</tt> template. <tt class="literal">retype</tt> has template arguments
	just like <tt class="literal">sigc::signal</tt> - return value, signal types.</p><p>It's a function template that takes a <tt class="literal">sigc::slot</tt>, and returns a <tt class="literal">sigc::slot</tt>. eg.</p><pre class="programlisting">
void dostuff(double foo)
{
}

sigc::signal&lt;void,int&gt; asignal;

asignal.connect(  sigc::retype&lt;void, int&gt;( slot(&amp;dostuff) )  );
</pre><p>If you only want to change the return type, you can use <tt class="literal">sigc::retype_return</tt>.
	<tt class="literal">retype_return</tt> needs only one template argument.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch04.html">Prev</a></td><td width="20%" align="center"><a accesskey="u" href="ch04.html">Up</a></td><td width="40%" align="right"><a accesskey="n" href="ch04s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter4.Advanced topics</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">Marshallers</td></tr></table></div></body></html>