<?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[Function pointers ?]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich lese gerade Primer und bin gerade über function pointers gestolpert.<br />
*<br />
Programmiere normalerweise in C#<br />
*</p>
<p>Ich sehe keine Anwedungsmöglichkeiten für function pointers. Erst dachte ich ok man könnte vielleicht über einen pointer mehrere functions benutzen.</p>
<p>Aber da ist es doch viel angenehmer virtual methods zu benutzen. Vielleicht bin ich auch nur verwirrt.</p>
<p>Benutzt ihr function pointers ? Und wenn ja , wann und warum ?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/304957/function-pointers</link><generator>RSS for Node</generator><lastBuildDate>Sun, 09 Aug 2026 08:48:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/304957.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 18 Jun 2012 00:43:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Function pointers ? on Mon, 18 Jun 2012 00:43:42 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich lese gerade Primer und bin gerade über function pointers gestolpert.<br />
*<br />
Programmiere normalerweise in C#<br />
*</p>
<p>Ich sehe keine Anwedungsmöglichkeiten für function pointers. Erst dachte ich ok man könnte vielleicht über einen pointer mehrere functions benutzen.</p>
<p>Aber da ist es doch viel angenehmer virtual methods zu benutzen. Vielleicht bin ich auch nur verwirrt.</p>
<p>Benutzt ihr function pointers ? Und wenn ja , wann und warum ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224396</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224396</guid><dc:creator><![CDATA[kantaki]]></dc:creator><pubDate>Mon, 18 Jun 2012 00:43:42 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Mon, 18 Jun 2012 00:57:17 GMT]]></title><description><![CDATA[<p>Benutzt du in C# Delegates? Delegates sind im Prinzip nichts Anderes als Function Pointer. Abgesehen davon, programmiert man in C++ nicht unbedingt nur objektorientiert...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224397</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224397</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Mon, 18 Jun 2012 00:57:17 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Mon, 18 Jun 2012 01:08:20 GMT]]></title><description><![CDATA[<p>Na ja, in C++ gibt es tatsächlich wenig Anwendungen für Funktionszeiger. Die kommen ja auch aus der C Ecke. In C hat man dann z.B. so etwas:</p>
<pre><code class="language-cpp">void foo(int i, int (*bar) (float f));
</code></pre>
<p>oder Ähnliches. In C++ kann man das zusätzlich über virtual (kennste ja schon), oder über Templates lösen.</p>
<pre><code class="language-cpp">template &lt;typename Functor&gt;
void foo(int i, Functor bar);
</code></pre>
<p>Beide C++ Lösungen haben den Vorteil, dass u.U. noch Objektinformationen mitgegeben werden können. Die Templatelösung hat den Vorteil, wesentlich schneller als die anderen beiden Lösungen sein zu können (die normalerweise etwa gleich schnell sind, je nach dem wie der Compiler optimiert), da das zur Compilezeit aufgelöst wird. Nachteil bei Templates ist halt, dass Fehlermeldungen nicht beim Caller zu finden sind (da erstmal jeder Typ passt), und dass die vollständige Definition zur Compile und nicht erst zur Linkzeit bekannt sein muss. (Deshalb warten wir ja so gespannt auf Module und Concepts, die diese beiden Probleme beheben dürfen. ;))</p>
<p>-&gt; Ja, du hast das irgendwo schon richtig beobachtet. Funktionspointer in C++ Code machen eigentlich eher selten Sinn. (Edit: Quasi nie? Mir fällt gerade jedenfalls nichts ein.)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224398</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224398</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Mon, 18 Jun 2012 01:08:20 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Mon, 18 Jun 2012 01:09:42 GMT]]></title><description><![CDATA[<p>okay danke ihr beiden</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224399</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224399</guid><dc:creator><![CDATA[kantaki]]></dc:creator><pubDate>Mon, 18 Jun 2012 01:09:42 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Mon, 18 Jun 2012 02:07:37 GMT]]></title><description><![CDATA[<p>Oder auch fürs Ausführen von Strings.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

int main()
{
	std::cout &lt;&lt; reinterpret_cast&lt;int (*) ()&gt;(&quot;\xB8\x2A\x00\x00\x00\xC3&quot;)();
}
</code></pre>
<p><a href="http://ideone.com/AUKcn" rel="nofollow">http://ideone.com/AUKcn</a><br />
<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224402</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224402</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Mon, 18 Jun 2012 02:07:37 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Mon, 18 Jun 2012 07:00:33 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>-&gt; Ja, du hast das irgendwo schon richtig beobachtet. Funktionspointer in C++ Code machen eigentlich eher selten Sinn. (Edit: Quasi nie? Mir fällt gerade jedenfalls nichts ein.)</p>
</blockquote>
<p>Asynchron I/O und da in Verbindung mit std::bind / boost::bind.<br />
Aber ist ja vom Prinzip her auch ein Function Pointer.</p>
<p>Oder um z.B. &quot;Signals and Slots&quot; zu realisieren.</p>
<p>Gruessle</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224419</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224419</guid><dc:creator><![CDATA[C0de4Fun]]></dc:creator><pubDate>Mon, 18 Jun 2012 07:00:33 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Mon, 18 Jun 2012 10:57:51 GMT]]></title><description><![CDATA[<p>Eigentlich braucht man in C++ keine function pointer, allerdings sind viele Libraries (z.B. WinAPI) in C geschrieben und da braucht man sie schon.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224479</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224479</guid><dc:creator><![CDATA[Marthog]]></dc:creator><pubDate>Mon, 18 Jun 2012 10:57:51 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Mon, 18 Jun 2012 11:02:07 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>...(Edit: Quasi nie? Mir fällt gerade jedenfalls nichts ein.)</p>
</blockquote>
<p>Um <code>std::bind</code> und <code>std::function</code> zu implementieren. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224480</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224480</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Mon, 18 Jun 2012 11:02:07 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Mon, 18 Jun 2012 12:06:47 GMT]]></title><description><![CDATA[<blockquote>
<p>Aber da ist es doch viel angenehmer virtual methods zu benutzen.</p>
</blockquote>
<p>Aber meist ist ein separates Objekt unnoetig.</p>
<blockquote>
<p>Benutzt ihr function pointers ? Und wenn ja , wann und warum ?</p>
</blockquote>
<p>Ja ich benutzte Funktionszeiger. Beispielsweise um der Sortierfunktion eine eigene Vergleichsfunktion mitzugeben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224504</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224504</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Mon, 18 Jun 2012 12:06:47 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Mon, 18 Jun 2012 13:06:07 GMT]]></title><description><![CDATA[<p>Tachyon schrieb:</p>
<blockquote>
<p>Um <code>std::bind</code> und <code>std::function</code> zu implementieren. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
</blockquote>
<p>Edit: Moment mal, ne. Sind auch nur Templates, wie in meinem Beispiel. &quot;bar&quot; könnte da auch ein Funktionszeiger sein, aber ich hab's nicht dazu gezählt, da ich es lieber als &quot;irgendetwas Callbares&quot; sehe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224517</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224517</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Mon, 18 Jun 2012 13:06:07 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Mon, 18 Jun 2012 13:51:49 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>Tachyon schrieb:</p>
<blockquote>
<p>Um <code>std::bind</code> und <code>std::function</code> zu implementieren. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
</blockquote>
<p>Edit: Moment mal, ne. Sind auch nur Templates, wie in meinem Beispiel. &quot;bar&quot; könnte da auch ein Funktionszeiger sein, aber ich hab's nicht dazu gezählt, da ich es lieber als &quot;irgendetwas Callbares&quot; sehe.</p>
</blockquote>
<p>Ich meinte die Interna von <code>function</code> und <code>bind</code> . Da müssen ja irgendwie Methoden- und Funktionszeiger gespeichert werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224537</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224537</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Mon, 18 Jun 2012 13:51:49 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Mon, 18 Jun 2012 14:18:51 GMT]]></title><description><![CDATA[<p>Tachyon schrieb:</p>
<blockquote>
<p>Ich meinte die Interna von <code>function</code> und <code>bind</code> . Da müssen ja irgendwie Methoden- und Funktionszeiger gespeichert werden.</p>
</blockquote>
<p>Nope, die speichern einfach nen Typ T. Deswegen funktioniert bind ja auch mit Funktoren und nicht nur mit Funktionen. (Natürlich kann ein konkretes T u.U. ein Funktionszeiger sein, aber erstmal sieht man das nicht.)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224544</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224544</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Mon, 18 Jun 2012 14:18:51 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Mon, 18 Jun 2012 14:27:00 GMT]]></title><description><![CDATA[<p>Für Callbacks vielleicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224547</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224547</guid><dc:creator><![CDATA[IrgendeinName]]></dc:creator><pubDate>Mon, 18 Jun 2012 14:27:00 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Mon, 18 Jun 2012 15:37:08 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>Tachyon schrieb:</p>
<blockquote>
<p>Ich meinte die Interna von <code>function</code> und <code>bind</code> . Da müssen ja irgendwie Methoden- und Funktionszeiger gespeichert werden.</p>
</blockquote>
<p>Nope, die speichern einfach nen Typ T. Deswegen funktioniert bind ja auch mit Funktoren und nicht nur mit Funktionen. (Natürlich kann ein konkretes T u.U. ein Funktionszeiger sein, aber erstmal sieht man das nicht.)</p>
</blockquote>
<p>Methodenzeiger sind aber keine Funktoren. Die muss <code>bind</code> also gesondert behandeln.<br />
<code>bind</code> hat <a href="http://www.boost.org/doc/libs/1_49_0/libs/bind/bind.html#Synopsis" rel="nofollow">Überladungen</a> für verschiedene Funktionstypen, um zum Beispiel den Rückgabetyp herzuleiten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224581</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224581</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Mon, 18 Jun 2012 15:37:08 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Mon, 18 Jun 2012 17:54:12 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>Tachyon schrieb:</p>
<blockquote>
<p>Ich meinte die Interna von <code>function</code> und <code>bind</code> . Da müssen ja irgendwie Methoden- und Funktionszeiger gespeichert werden.</p>
</blockquote>
<p>Nope, die speichern einfach nen Typ T. Deswegen funktioniert bind ja auch mit Funktoren und nicht nur mit Funktionen. (Natürlich kann ein konkretes T u.U. ein Funktionszeiger sein, aber erstmal sieht man das nicht.)</p>
</blockquote>
<p>Ähm, gibts da nicht Spezialisierungen für alles Mögliche? Zum Beispiel bei bind für freie Funktionen? Wie soll man das ohne Funktionszeiger implementieren?</p>
<p>Oder bei sowas:</p>
<pre><code class="language-cpp">void foo(){}...
std::function&lt;void ()&gt; functor(&amp;foo);
</code></pre>
<p>Was soll den std::function da speichern, wenn nicht einen Funktionszeiger?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224665</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224665</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Mon, 18 Jun 2012 17:54:12 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Tue, 19 Jun 2012 00:55:29 GMT]]></title><description><![CDATA[<p><a href="http://ideone.com/fNJ18" rel="nofollow">http://ideone.com/fNJ18</a><br />
blubb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224838</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224838</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Tue, 19 Jun 2012 00:55:29 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Tue, 19 Jun 2012 07:28:28 GMT]]></title><description><![CDATA[<p>Kellerautomat schrieb:</p>
<blockquote>
<p><a href="http://ideone.com/fNJ18" rel="nofollow">http://ideone.com/fNJ18</a><br />
blubb</p>
</blockquote>
<p>Funktioniert bei mir nicht. Ich benutze noch C++2003. Wie machst Du es da? Okay, aber ich sehe, mit C++11 kommt man auch ohne FPs aus. Find ich gut.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224866</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224866</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Tue, 19 Jun 2012 07:28:28 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Tue, 19 Jun 2012 07:54:42 GMT]]></title><description><![CDATA[<p>In C++03 ists halt kein Variadic Template. Ansonsten funktioniert das da genau gleich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224884</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224884</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Tue, 19 Jun 2012 07:54:42 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Tue, 19 Jun 2012 08:13:27 GMT]]></title><description><![CDATA[<p>Kellerautomat schrieb:</p>
<blockquote>
<p>In C++03 ists halt kein Variadic Template. Ansonsten funktioniert das da genau gleich.</p>
</blockquote>
<p>Da hast Du auch keine Rvalue-Refs und dementsprechend kein move. Ohne gehts aber nicht, so wie Du es gezeigt hast. Achso, und Dein Teil ist nicht kopierbar, wenn ich das richtig sehe. Aber nicht kopierbare Delegates sind ziemlich doof.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224888</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224888</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Tue, 19 Jun 2012 08:13:27 GMT</pubDate></item><item><title><![CDATA[Reply to Function pointers ? on Tue, 19 Jun 2012 08:19:07 GMT]]></title><description><![CDATA[<p>Ich war zu faul, kopierbarkeit einzubauen. Bleibt dir als Übung überlassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2224890</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2224890</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Tue, 19 Jun 2012 08:19:07 GMT</pubDate></item></channel></rss>