<?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[[gelöst] template-abhängigen Funktionspointer übergeben geht nicht]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe einen Konstruktor einer Template-Klasse der einen Funktionspointer übernhmen soll, der vom Template-Parameter abhängt. Das sieht so aus:</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
class Foo
{
public:
    typedef void (*func)(T);
    Foo(T* ptr);
    Foo(func func_ptr);

private:
    T* m_ptr;
    func m_func_ptr;
};
</code></pre>
<p>Wenn ich sie jetzt mit einer void(bool) Funktion instantiieren will, geht das nicht:</p>
<pre><code class="language-cpp">void fun(bool b) { doSomethingWith(b); }
// ...

Foo* bar = new Foo&lt;bool&gt;(&amp;fun);
</code></pre>
<p>gibt mir in gcc 4.4:</p>
<pre><code>error: no matching function for call to ‘Foo&lt;bool&gt;::Foo(void* (*&amp;)(bool))’
note: candidates are: Foo&lt;T&gt;::Foo(void (*)(T)) [with T = bool] &lt;near match&gt;
</code></pre>
<p>Was habe ich hier übersehen?</p>
<p>Gruß,<br />
Phil</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/266749/gelöst-template-abhängigen-funktionspointer-übergeben-geht-nicht</link><generator>RSS for Node</generator><lastBuildDate>Wed, 02 Sep 2026 22:49:04 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/266749.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 13 May 2010 16:52:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [gelöst] template-abhängigen Funktionspointer übergeben geht nicht on Thu, 13 May 2010 17:15:18 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe einen Konstruktor einer Template-Klasse der einen Funktionspointer übernhmen soll, der vom Template-Parameter abhängt. Das sieht so aus:</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
class Foo
{
public:
    typedef void (*func)(T);
    Foo(T* ptr);
    Foo(func func_ptr);

private:
    T* m_ptr;
    func m_func_ptr;
};
</code></pre>
<p>Wenn ich sie jetzt mit einer void(bool) Funktion instantiieren will, geht das nicht:</p>
<pre><code class="language-cpp">void fun(bool b) { doSomethingWith(b); }
// ...

Foo* bar = new Foo&lt;bool&gt;(&amp;fun);
</code></pre>
<p>gibt mir in gcc 4.4:</p>
<pre><code>error: no matching function for call to ‘Foo&lt;bool&gt;::Foo(void* (*&amp;)(bool))’
note: candidates are: Foo&lt;T&gt;::Foo(void (*)(T)) [with T = bool] &lt;near match&gt;
</code></pre>
<p>Was habe ich hier übersehen?</p>
<p>Gruß,<br />
Phil</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1896763</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1896763</guid><dc:creator><![CDATA[PhilippM]]></dc:creator><pubDate>Thu, 13 May 2010 17:15:18 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] template-abhängigen Funktionspointer übergeben geht nicht on Thu, 13 May 2010 17:00:15 GMT]]></title><description><![CDATA[<p>Dein Code sieht aber anders aus, als den du präsentiert hast. Dein Konstruktor sieht nämlich so aus:</p>
<pre><code class="language-cpp">Foo(func&amp; func_ptr);
</code></pre>
<p>Nimm diese Referenz weg und übergibt den Zeiger als Kopie und alles funktioniert wie es soll. Wieso überhaupt als Referenz übergeben?</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1896765</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1896765</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Thu, 13 May 2010 17:00:15 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] template-abhängigen Funktionspointer übergeben geht nicht on Thu, 13 May 2010 17:02:01 GMT]]></title><description><![CDATA[<p>Ausserdem:</p>
<pre><code class="language-cpp">Foo&lt;bool&gt;* bar = new Foo&lt;bool&gt;(fun);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1896766</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1896766</guid><dc:creator><![CDATA[Zeus]]></dc:creator><pubDate>Thu, 13 May 2010 17:02:01 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] template-abhängigen Funktionspointer übergeben geht nicht on Thu, 13 May 2010 17:09:17 GMT]]></title><description><![CDATA[<p>Hessisches Universalfragewort: Hä?</p>
<p>Also ja, da ist noch eine Indirektionsebene dazwischen.<br />
Der konkrete Aufruf sieht so aus:</p>
<pre><code class="language-cpp">void fun(bool b) { doSomethingWith(b); }
</code></pre>
<pre><code class="language-cpp">requestData(&amp;fun);
</code></pre>
<p>wobei die requestData()-Funktion folgendes macht:</p>
<pre><code class="language-cpp">requestData(void(*fun(bool)))
{
    Foo&lt;bool&gt;* bar = new Foo&lt;bool&gt;(fun)));
    // ...
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1896768</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1896768</guid><dc:creator><![CDATA[PhilippM]]></dc:creator><pubDate>Thu, 13 May 2010 17:09:17 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] template-abhängigen Funktionspointer übergeben geht nicht on Thu, 13 May 2010 17:15:44 GMT]]></title><description><![CDATA[<p>Sorry, ich bin dämlich.</p>
<p>Die Funktionssignatur muss natürlich</p>
<pre><code class="language-cpp">requestData(void(*)(bool));

requestData(void(*func)(bool)) {
    Foo&lt;bool&gt; bar = new Foo&lt;bool&gt;(func);
}
</code></pre>
<p>lauten.</p>
<p>So geht's.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1896771</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1896771</guid><dc:creator><![CDATA[PhilippM]]></dc:creator><pubDate>Thu, 13 May 2010 17:15:44 GMT</pubDate></item></channel></rss>