<?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[Funktionszeiger]]></title><description><![CDATA[<p>Hallo.</p>
<p>Ich probiere gerade ein paar Spielereien mit Templates und Funktionszeigern aus und habe zwei Probleme.</p>
<ol>
<li></li>
</ol>
<pre><code>template&lt;typename T&gt;
void f(T)
{
}

void g();

int main()
{
	f(g);
}
</code></pre>
<p>Dieser Code erzeugt einen Linker-Fehler. Meiner Meinung nach ungerechtfertigt. Behalte ich recht?</p>
<p>2. Ich weiss, dass ich die korrekte Überladung einer Funktion mit einem expliziten Cast des Zeigers wählen kann. Beispielsweise:</p>
<pre><code>std::cout &lt;&lt; f(static_cast&lt;float(*)(char)&gt;(g));
</code></pre>
<p>Geht das auch irgendwie ohne dass ich den Rückgabetypen angeben muss? Der gehört ja schliesslich nicht zur Signatur der Funktion.</p>
<p>Gruss.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/326781/funktionszeiger</link><generator>RSS for Node</generator><lastBuildDate>Tue, 26 May 2026 03:23:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/326781.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 07 Jul 2014 09:06:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Funktionszeiger on Mon, 07 Jul 2014 09:06:21 GMT]]></title><description><![CDATA[<p>Hallo.</p>
<p>Ich probiere gerade ein paar Spielereien mit Templates und Funktionszeigern aus und habe zwei Probleme.</p>
<ol>
<li></li>
</ol>
<pre><code>template&lt;typename T&gt;
void f(T)
{
}

void g();

int main()
{
	f(g);
}
</code></pre>
<p>Dieser Code erzeugt einen Linker-Fehler. Meiner Meinung nach ungerechtfertigt. Behalte ich recht?</p>
<p>2. Ich weiss, dass ich die korrekte Überladung einer Funktion mit einem expliziten Cast des Zeigers wählen kann. Beispielsweise:</p>
<pre><code>std::cout &lt;&lt; f(static_cast&lt;float(*)(char)&gt;(g));
</code></pre>
<p>Geht das auch irgendwie ohne dass ich den Rückgabetypen angeben muss? Der gehört ja schliesslich nicht zur Signatur der Funktion.</p>
<p>Gruss.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407345</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407345</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Mon, 07 Jul 2014 09:06:21 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionszeiger on Mon, 07 Jul 2014 09:18:31 GMT]]></title><description><![CDATA[<p>Nein, du hast unrecht.<br />
Du brauchst die Definition der Funktion g, damit deren Adresse als Template Argument übergeben werden kann, selbst wenn du die Funktion nicht aufrufst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407347</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407347</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Mon, 07 Jul 2014 09:18:31 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionszeiger on Mon, 07 Jul 2014 09:41:15 GMT]]></title><description><![CDATA[<blockquote>
<p>Behalte ich recht?</p>
</blockquote>
<p>Nein - es gibt einen <em>odr-use</em> von <code>g</code> . Daher muss <code>g</code> definiert sein. Clang ist nicht standardkonform.</p>
<p>Zu deinem anderen Problem:</p>
<pre><code>void g(int, long long, float) {}
void g(char, long, double) {}

template &lt;typename T&gt;
struct identity
{  using type = T;  };

template &lt;typename... T&gt;
struct deduce_impl
{
	template &lt;typename R, typename... Superfluent&gt;
	static typename identity&lt;R(*)(T..., Superfluent...)&gt;::type from( R(*f)(T..., Superfluent...) )
	{
		return f;
	}
};

template &lt;typename Call&gt;
void bar(Call){}

int main()
{
	bar( deduce_impl&lt;char&gt;::from(g) );
}
</code></pre>
<p>Kannst du in ein Makro packen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407352</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407352</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Mon, 07 Jul 2014 09:41:15 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionszeiger on Mon, 07 Jul 2014 09:43:23 GMT]]></title><description><![CDATA[<p>Arcoth, mal eine Frage: Wieso identity?<br />
Tuts nicht einfach R(*)(T..., Superfluent...) als return type direkt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407354</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407354</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Mon, 07 Jul 2014 09:43:23 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionszeiger on Mon, 07 Jul 2014 09:48:13 GMT]]></title><description><![CDATA[<blockquote>
<p>Tuts nicht einfach R(*)(T..., Superfluent...) als return type direkt?</p>
</blockquote>
<p>Nö, leider nicht.</p>
<p>Mir fällt aber sowieso gerade auf dass das Unsinn ist.</p>
<pre><code>template &lt;typename R, typename... Superfluent&gt;
    static auto from( R(*f)(T..., Superfluent...) ) -&gt; decltype(f)
    {
        return f;
    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2407356</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407356</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Mon, 07 Jul 2014 09:48:13 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionszeiger on Mon, 07 Jul 2014 10:07:21 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<blockquote>
<p>Behalte ich recht?</p>
</blockquote>
<p>Nein - es gibt einen <em>odr-use</em> von <code>g</code> . Daher muss <code>g</code> definiert sein. Clang ist nicht standardkonform.</p>
</blockquote>
<p>ODR-Verletzungen bedürfen in der Regel keiner Diagnose...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407360</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407360</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 07 Jul 2014 10:07:21 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionszeiger on Mon, 07 Jul 2014 10:51:01 GMT]]></title><description><![CDATA[<p>Hallo.</p>
<p>Erstens erscheint mir nun völlig logisch, da hätte ich auch selbst drauf kommen können. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>Arcoth schrieb:</p>
<blockquote>
<p>Clang ist nicht standardkonform.</p>
</blockquote>
<p>Ebenso GCC 4.8.1</p>
<p>Zu zweitens:<br />
Danke Moderator Arcoth, super Lösung. Ich denke, mit einer knackigen kurzen Bezeichnung ist nicht einmal ein Makro nötig.</p>
<p>Schönen Tag noch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407368</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407368</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Mon, 07 Jul 2014 10:51:01 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionszeiger on Mon, 07 Jul 2014 11:00:20 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>Clang ist nicht standardkonform.</p>
</blockquote>
<p>Nochmal selbst getested. clang steigt mit einem Linkerfehler aus. Was soll daran nicht standardkonform sein? Der Compiler kann sich ja gar nicht beschweren, schließlich könnte g ja auch in einer anderen ÜE definiert sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407369</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407369</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 07 Jul 2014 11:00:20 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionszeiger on Mon, 07 Jul 2014 11:21:53 GMT]]></title><description><![CDATA[<blockquote>
<p>clang steigt mit einem Linkerfehler aus</p>
</blockquote>
<p>Nicht bei mir.</p>
<pre><code>void g(int, long long, float);
void g(char, long, double);

template &lt;typename T&gt;
struct identity
{  using type = T;  };

template &lt;typename... T&gt;
struct deduce_impl
{
	template &lt;typename R, typename... Superfluent&gt;
	static auto from( R(*f)(T..., Superfluent...) ) -&gt; decltype(f)
	{
		return f;
	}
};

template &lt;typename Call&gt;
void bar(Call){}

int main()
{
	bar( deduce_impl&lt;char&gt;::from(g) );
}
</code></pre>
<pre><code>clang++ -O3 -std=c++1y ...
</code></pre>
<p>Kompiliert (und linkt) einwandfrei.</p>
<p>Liegt wohl am Optimierungsflag -O3, dasselbe Ergebnis mit GCC (4.9)... hihi, mein Fehler. Entschuldige. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<blockquote>
<p>ODR-Verletzungen bedürfen in der Regel keiner Diagnose...</p>
</blockquote>
<p>Ja, aber laufen kann das Programm wohl nicht, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407370</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407370</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Mon, 07 Jul 2014 11:21:53 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionszeiger on Mon, 07 Jul 2014 12:09:22 GMT]]></title><description><![CDATA[<p>VS2013 sagt sowohl in Debug als auch in Release</p>
<blockquote>
<p>error LNK2001: unresolved external symbol &quot;void __cdecl g(char,long,double)&quot;</p>
</blockquote>
<p>Ich schwöre ich habe keine Drogen genommen, aber da steht Arcoth Moderator. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407380</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407380</guid><dc:creator><![CDATA[nwp3]]></dc:creator><pubDate>Mon, 07 Jul 2014 12:09:22 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionszeiger on Mon, 07 Jul 2014 12:39:08 GMT]]></title><description><![CDATA[<p>nwp3 schrieb:</p>
<blockquote>
<p>Ich schwöre ich habe keine Drogen genommen, aber da steht Arcoth Moderator. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
</blockquote>
<p><a href="http://www.c-plusplus.net/forum/p2406401#2406401" rel="nofollow">http://www.c-plusplus.net/forum/p2406401#2406401</a></p>
<p>@Arcoth:<br />
Mir ist klar, dass die Syntax dafür beschissen ist, aber gibt es nocht einen anderen Grund? Oder ist das einfach nur für eine schönere Syntax?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407390</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407390</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Mon, 07 Jul 2014 12:39:08 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionszeiger on Mon, 07 Jul 2014 12:44:03 GMT]]></title><description><![CDATA[<p>nwp3 schrieb:</p>
<blockquote>
<p>VS2013 sagt sowohl in Debug als auch in Release</p>
<blockquote>
<p>error LNK2001: unresolved external symbol &quot;void __cdecl g(char,long,double)&quot;</p>
</blockquote>
</blockquote>
<p>Ja, mit VS2013 hab ich es auch ursprünglich getestet und den Fehler erhalten.</p>
<p>nwp3 schrieb:</p>
<blockquote>
<p>Ich schwöre ich habe keine Drogen genommen, aber da steht Arcoth Moderator. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
</blockquote>
<p>Bei mir auch, und? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /><br />
Vielleicht ist es ein wenig falsch 'rübergekommen. Das war nicht ironisch gemeint oder so sondern soll in leichter Form zur Erkürung zum Moderator gratulieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2407394</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2407394</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Mon, 07 Jul 2014 12:44:03 GMT</pubDate></item></channel></rss>