<?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[Funktionen in einer Liste oder einem Array]]></title><description><![CDATA[<p>Hallo,</p>
<p>Ich bin relativ neu im programmieren mit c++ und wollte fragen ob es irgendwie möglich ist funktionen in einer liste oder einem array zu speichern.<br />
Ich möchte gerne einen threadpool schreiben bei dem man neue funktionen über eine methode addFunction zu einer liste oder einem array hinzufügt.<br />
Ist das überhaupt möglich und wenn ja welchen typ muss dann die liste haben?<br />
Wie würde man soetwas sonst programmieren?<br />
Etwas ähnliches habe ich in python schonmal geschrieben, aber in pythons listen kann man alle typen gemischt halten.</p>
<p>MfG init-0</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/313238/funktionen-in-einer-liste-oder-einem-array</link><generator>RSS for Node</generator><lastBuildDate>Sat, 01 Aug 2026 18:38:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/313238.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 24 Jan 2013 18:35:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Funktionen in einer Liste oder einem Array on Thu, 24 Jan 2013 18:35:01 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Ich bin relativ neu im programmieren mit c++ und wollte fragen ob es irgendwie möglich ist funktionen in einer liste oder einem array zu speichern.<br />
Ich möchte gerne einen threadpool schreiben bei dem man neue funktionen über eine methode addFunction zu einer liste oder einem array hinzufügt.<br />
Ist das überhaupt möglich und wenn ja welchen typ muss dann die liste haben?<br />
Wie würde man soetwas sonst programmieren?<br />
Etwas ähnliches habe ich in python schonmal geschrieben, aber in pythons listen kann man alle typen gemischt halten.</p>
<p>MfG init-0</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2293111</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2293111</guid><dc:creator><![CDATA[init-0]]></dc:creator><pubDate>Thu, 24 Jan 2013 18:35:01 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionen in einer Liste oder einem Array on Thu, 24 Jan 2013 18:42:28 GMT]]></title><description><![CDATA[<p>Ja, das ist möglich. Schau dir dazu folgende Konzepte an: STL-Container, Funktionszeiger, Funktionsobjekte (speziell <code>std::function</code> ).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2293117</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2293117</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Thu, 24 Jan 2013 18:42:28 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionen in einer Liste oder einem Array on Thu, 24 Jan 2013 18:42:45 GMT]]></title><description><![CDATA[<p>Das Stichwort ist function pointer.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2293118</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2293118</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Thu, 24 Jan 2013 18:42:45 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionen in einer Liste oder einem Array on Thu, 12 Jun 2014 11:42:59 GMT]]></title><description><![CDATA[<p>...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2293122</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2293122</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Thu, 12 Jun 2014 11:42:59 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionen in einer Liste oder einem Array on Thu, 24 Jan 2013 19:35:21 GMT]]></title><description><![CDATA[<p>Ich wollte einfach nur einen Anreiz zum googeln geben. ^^<br />
Natürlich ist std::function besser.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2293149</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2293149</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Thu, 24 Jan 2013 19:35:21 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionen in einer Liste oder einem Array on Mon, 11 Feb 2013 19:27:51 GMT]]></title><description><![CDATA[<p>Tut mir leid, dass es so lange gedauert hat hier zu antworten.<br />
Ich habe jetzt versucht das ganze zusammen zu schreiben.<br />
<a href="http://en.cppreference.com/w/cpp/utility/functional/function" rel="nofollow">http://en.cppreference.com/w/cpp/utility/functional/function</a> habe ich als Quelle für die lambdas benutzt.<br />
Was ich eigentlich haben will ist so etwas:</p>
<pre><code>class ThreadPool{
	FUNCLIST queue;

	void addFunction(std::function&lt;void&gt; func){
		this-&gt;queue.insert(this-&gt;queue.end(), func);
	}
}
</code></pre>
<p>Aber zuerst habe ich versucht die queue im konstruktor zu benutzen:</p>
<pre><code>#include &lt;list&gt;
#include &lt;functional&gt;

typedef std::list&lt;std::function&lt;void&gt;&gt; FUNCLIST;

void print_num(int i)
{
    printf(&quot;%d&quot;, i);
}

class ThreadPool{
	FUNCLIST queue;

	ThreadPool(){
		std::function&lt;void&gt; f_display_42 = []() { print_num(42); };
		this-&gt;queue.insert(this-&gt;queue.end(), f_display_42);
	}
}
</code></pre>
<p>Leider verstehe ich die Fehlermeldung nicht so ganz:</p>
<pre><code>1&gt;------ Build started: Project: GET, Configuration: Debug Win32 ------
1&gt;  GET.cpp
1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(554): error C2027: use of undefined type 'std::_Get_function_impl&lt;_Tx&gt;'
1&gt;          with
1&gt;          [
1&gt;              _Tx=void
1&gt;          ]
1&gt;          c:\users\robin\documents\visual studio 2012\projects\get\get\threading.h(16) : see reference to class template instantiation 'std::function&lt;_Fty&gt;' being compiled
1&gt;          with
1&gt;          [
1&gt;              _Fty=void
1&gt;          ]
1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(555): error C2504: 'type' : base class undefined
1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(558): error C2027: use of undefined type 'std::_Get_function_impl&lt;_Tx&gt;'
1&gt;          with
1&gt;          [
1&gt;              _Tx=void
1&gt;          ]
1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(558): error C2146: syntax error : missing ';' before identifier '_Mybase'
1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(558): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2297985</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2297985</guid><dc:creator><![CDATA[init-0]]></dc:creator><pubDate>Mon, 11 Feb 2013 19:27:51 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionen in einer Liste oder einem Array on Mon, 11 Feb 2013 20:20:59 GMT]]></title><description><![CDATA[<p>Aus Deinem Link:</p>
<pre><code class="language-cpp">template&lt; class R, class... Args &gt;
class function&lt;R(Args...)&gt;
</code></pre>
<p>Eine Funktion ohne Parameter, die nix zurückgibt:</p>
<pre><code class="language-cpp">std::function&lt;void()&gt; f = [](){};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2297997</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2297997</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Mon, 11 Feb 2013 20:20:59 GMT</pubDate></item></channel></rss>