<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Template auf boost::function]]></title><description><![CDATA[<p>Ich will ein Template auf boost::function erstellen.<br />
So:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;boost/function.hpp&gt;

class X
{
public:
    void Func ( int x ) { std::cout &lt;&lt; x &lt;&lt; std::endl ; }
};

int main()
{
    template&lt;class T&gt;
    boost::function&lt;void(T*,int)&gt; MyFunc ;
    MyFunc = &amp;T::Func ;
    X x ;
    MyFunc(&amp;x,2) ;
}
</code></pre>
<p>Fehler:</p>
<pre><code>In function ‘int main()’:|
error: expected primary-expression before ‘template’|
error: expected ‘;’ before ‘template’|
error: ‘MyFunc’ was not declared in this scope|
error: ‘T’ has not been declared|
||=== Build finished: 4 errors, 0 warnings ===|
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/262315/template-auf-boost-function</link><generator>RSS for Node</generator><lastBuildDate>Sun, 06 Sep 2026 17:03:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/262315.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 04 Mar 2010 08:14:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Template auf boost::function on Thu, 04 Mar 2010 08:14:22 GMT]]></title><description><![CDATA[<p>Ich will ein Template auf boost::function erstellen.<br />
So:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;boost/function.hpp&gt;

class X
{
public:
    void Func ( int x ) { std::cout &lt;&lt; x &lt;&lt; std::endl ; }
};

int main()
{
    template&lt;class T&gt;
    boost::function&lt;void(T*,int)&gt; MyFunc ;
    MyFunc = &amp;T::Func ;
    X x ;
    MyFunc(&amp;x,2) ;
}
</code></pre>
<p>Fehler:</p>
<pre><code>In function ‘int main()’:|
error: expected primary-expression before ‘template’|
error: expected ‘;’ before ‘template’|
error: ‘MyFunc’ was not declared in this scope|
error: ‘T’ has not been declared|
||=== Build finished: 4 errors, 0 warnings ===|
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1864105</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1864105</guid><dc:creator><![CDATA[nami]]></dc:creator><pubDate>Thu, 04 Mar 2010 08:14:22 GMT</pubDate></item><item><title><![CDATA[Reply to Template auf boost::function on Thu, 04 Mar 2010 09:11:21 GMT]]></title><description><![CDATA[<p>nami schrieb:</p>
<blockquote>
<p>Ich will ein Template auf boost::function erstellen.</p>
</blockquote>
<p>Du willst <strong>was</strong>? Den Terminus &quot;Template auf XY erstellen&quot; gibts nicht.</p>
<p>Du kannst entweder ein Klassentemplate oder ein Funktionstemplate deklarieren oder definieren.</p>
<p>- Klassentemplates werden deklariert nach dem schema</p>
<pre><code class="language-cpp">template &lt;[templatemparameter]&gt;
class|struct Name;
</code></pre>
<p>, bei der Definition kommt noch die Liste der Basisklassen und der Definitionsrumpf (Geschweifte Klammern mit Membern, typedefs, Methoden, friends, zugriffsspezifizierern usw.) hinzu.</p>
<p>- Funktionstemplates werden deklariert nach dem Schema</p>
<pre><code class="language-cpp">template &lt;[templateparameter]&gt;
[Rückgabetyp] FunktionsName([Argumentliste]);
</code></pre>
<p>, bei der Definition entfällt das Semikolon und es folgt der Funktionsrumpf (Geschweifte Klammern mit Ausdrücken)<br />
Funktionstemplates dürfen außerdem wie alle Funktionen nicht innerhalb von anderen Funktionsdefinitionen definiert werden.</p>
<p>Fürs Klassentemplate fehlt also zumindest das schlüsselwort class oder struct, ein funktionstemplate kann an der Stelle nicht definiert werden und es fehlen so oder so die Klammern für die Argumentliste.</p>
<p>Also nochmal von vorne: was willst du <em>erreichen</em>, was ist deine Idee, <em>wie</em> du es evtl. erreichen könntest. Bitte in klaren Worten die jeder versteht und wenn möglich etwas mehr als ein halber Satz.<br />
Siehe auch Link in meiner Signatur.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1864130</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1864130</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 04 Mar 2010 09:11:21 GMT</pubDate></item><item><title><![CDATA[Reply to Template auf boost::function on Thu, 04 Mar 2010 10:09:48 GMT]]></title><description><![CDATA[<p>nami schrieb:</p>
<blockquote>
<p>:</p>
<pre><code class="language-cpp">template&lt;class T&gt;
    boost::function&lt;void(T*,int)&gt; MyFunc ;
    MyFunc = &amp;T::Func ;
    X x ;
    MyFunc(&amp;x,2) ;
</code></pre>
</blockquote>
<p>Du musst MyFunc schon einen richtigen Typen geben. ZB so:</p>
<pre><code class="language-cpp">boost::function&lt;void(X*,int)&gt; MyFunc = &amp;X::Func;
    X x;
    MyFunc(&amp;x,2);
</code></pre>
<p>Was willst Du denn hier durch ein <code>template&lt;class T&gt;</code> erreichen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1864155</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1864155</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Thu, 04 Mar 2010 10:09:48 GMT</pubDate></item><item><title><![CDATA[Reply to Template auf boost::function on Thu, 04 Mar 2010 10:23:22 GMT]]></title><description><![CDATA[<p>Willst Du vielleicht so etwas hier?</p>
<pre><code class="language-cpp">using boost::function;
  using boost::bind;
  using boost::_1;

  X x;
  function&lt;void(int)&gt; myfunc = bind(&amp;X::Func, &amp;x, _1);
  myfunc(2);
</code></pre>
<p>Hier hängt der Typ von myfunc nicht von X ab.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1864160</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1864160</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Thu, 04 Mar 2010 10:23:22 GMT</pubDate></item></channel></rss>