<?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[Eine Funktion als Parameter angeben]]></title><description><![CDATA[<p>Hallo Community<br />
kann ich eigentlich eine Funktion als Parameter einer anderen Funktion angeben?<br />
Müsste doch im Grunde irgendwie funktionieren, immerhin hat sie ja auch eine Adresse im Code Segment. Diese Adresse könnte ich doch als Parameter mit angeben.<br />
Doch wie mach ich das, denn das müsste ich doch dann auch bei der deklaration mit angeben???</p>
<p>Beispiel:</p>
<pre><code class="language-cpp">void TargetFunc();          //Diese Funktion soll ausgeführt werden
void CallFunc(void *Func());

int main(){
    CallFunc(&amp;TargetFunc());
    return 0;
}

void TargetFunc(){
    cout &lt;&lt; &quot;Hallo&quot; &lt;&lt; endl;
}

void CallFunc(void *Func()){
    Func();
}
</code></pre>
<p>Es soll jetzt hier auch erstmal nicht um den Sinn gehen, sondern nur ob es möglich ist</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/237274/eine-funktion-als-parameter-angeben</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 14:27:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/237274.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 26 Mar 2009 16:19:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Eine Funktion als Parameter angeben on Thu, 26 Mar 2009 16:19:17 GMT]]></title><description><![CDATA[<p>Hallo Community<br />
kann ich eigentlich eine Funktion als Parameter einer anderen Funktion angeben?<br />
Müsste doch im Grunde irgendwie funktionieren, immerhin hat sie ja auch eine Adresse im Code Segment. Diese Adresse könnte ich doch als Parameter mit angeben.<br />
Doch wie mach ich das, denn das müsste ich doch dann auch bei der deklaration mit angeben???</p>
<p>Beispiel:</p>
<pre><code class="language-cpp">void TargetFunc();          //Diese Funktion soll ausgeführt werden
void CallFunc(void *Func());

int main(){
    CallFunc(&amp;TargetFunc());
    return 0;
}

void TargetFunc(){
    cout &lt;&lt; &quot;Hallo&quot; &lt;&lt; endl;
}

void CallFunc(void *Func()){
    Func();
}
</code></pre>
<p>Es soll jetzt hier auch erstmal nicht um den Sinn gehen, sondern nur ob es möglich ist</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1686451</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1686451</guid><dc:creator><![CDATA[seux]]></dc:creator><pubDate>Thu, 26 Mar 2009 16:19:17 GMT</pubDate></item><item><title><![CDATA[Reply to Eine Funktion als Parameter angeben on Thu, 26 Mar 2009 16:24:54 GMT]]></title><description><![CDATA[<p>CallFunc(TargetFunc);</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1686454</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1686454</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Thu, 26 Mar 2009 16:24:54 GMT</pubDate></item><item><title><![CDATA[Reply to Eine Funktion als Parameter angeben on Thu, 26 Mar 2009 16:27:12 GMT]]></title><description><![CDATA[<p>seux schrieb:</p>
<blockquote>
<p>kann ich eigentlich eine Funktion als Parameter einer anderen Funktion angeben?</p>
</blockquote>
<p>Da hast du mehrere Möglichkeiten:<br />
a) Funktionszeiger<br />
b) Funktoren (Funktionsobjekte)</p>
<p>Letztere sind eher der C++ Weg, wenn du später auch Methoden verwenden willst. Für letztere ist der TR1 (sofern vom Compiler unterstützt) oder Boost sehr interessant (std::tr1::function / boost::function vor allem in Kombination mit std::tr1::bind / boost::bind).</p>
<p>cu André</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1686456</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1686456</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Thu, 26 Mar 2009 16:27:12 GMT</pubDate></item><item><title><![CDATA[Reply to Eine Funktion als Parameter angeben on Thu, 26 Mar 2009 16:34:32 GMT]]></title><description><![CDATA[<p>Ja, das ist möglich. Hier mal ein kleines Beispiel:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;

void TargetFunc();
void OtherFunc();
void ErrorFunc();
void CallFunc(void (*Func) (void));

int main()
{
	void (*myFunc) (void) = NULL;

	int num;

	while (true)
	{
		std::cout &lt;&lt; &quot;Welche Funktion wollen Sie aufrufen?\nEingabe: &quot;;
		std::cin &gt;&gt; num;

		switch (num)
		{
			case 0:
				myFunc = TargetFunc;
				break;
			case 1:
				myFunc = OtherFunc;
				break;
			default:
				myFunc = ErrorFunc;
				break;
		}

		CallFunc(myFunc);

		std::cout &lt;&lt; std::endl;
	}

    return 0;
}

void TargetFunc()
{
	std::cout &lt;&lt; &quot;Hallo&quot; &lt;&lt; std::endl;
}

void OtherFunc()
{
	std::cout &lt;&lt; &quot;Other...&quot; &lt;&lt; std::endl;
}

void ErrorFunc()
{
	std::cout &lt;&lt; &quot;Error!!!&quot; &lt;&lt; std::endl;
}

void CallFunc(void (*Func) (void))
{
	Func();
}
</code></pre>
<p>Weitere findest du auch hier: <a href="http://tutorial.schornboeck.net/funkt_zeiger.htm" rel="nofollow">http://tutorial.schornboeck.net/funkt_zeiger.htm</a></p>
<p>Oder einfach bei Google nach &quot;Funktionszeiger&quot; suchen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1686462</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1686462</guid><dc:creator><![CDATA[BBB]]></dc:creator><pubDate>Thu, 26 Mar 2009 16:34:32 GMT</pubDate></item><item><title><![CDATA[Reply to Eine Funktion als Parameter angeben on Thu, 26 Mar 2009 16:36:43 GMT]]></title><description><![CDATA[<p>Jo danke das ging aber schnell <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>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/16666">@Shader</a> Of Mine: Danke, funktioniert aber nur, wenn in der Deklaration der Funktionsparameter nicht als Zeiger angegeben ist.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/14941">@asc</a>: ich werd das mit dem TR1 gleich mal ausprobieren. Ich verwende GNU GCC und da weiß ih nicht, ob der das unterstützt, werd gleich mal google fragen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1686464</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1686464</guid><dc:creator><![CDATA[seux]]></dc:creator><pubDate>Thu, 26 Mar 2009 16:36:43 GMT</pubDate></item></channel></rss>