<?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[anfänger-frage polymorphismus]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte eine Datenstuktur liste selbst schreiben und suche nach einer möglichkeit dieser Klasse eine funktion zu übergeben, so dass diese funktion<br />
für jedes Element der Liste ausgeführt wird.</p>
<p>Nochmal ausführlicher:<br />
ich habe:</p>
<pre><code class="language-cpp">class Liste{
 Node *next;
 Node *prev;
}
</code></pre>
<p>und könnte dieser Klasse jetzt natürlich für jede Aufgabe eine Funktion hinzufügen: void forEachPrint(), void forEachPlus1(), forEachSquare(), usw, usw,<br />
das scheint mir aber blöd.</p>
<p>ich hätte gerne eine Funktion die so aussieht:</p>
<pre><code>void do( hier übergebe ich funktion f)
{
  f(this);
  next-&gt;do(f)
}
</code></pre>
<p>wie geht das und kann ich im netz eine ausführliche erklärung dazu finden?</p>
<p>Liebe Grüße,<br />
Raphael</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/127195/anfänger-frage-polymorphismus</link><generator>RSS for Node</generator><lastBuildDate>Tue, 25 Aug 2026 00:17:47 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/127195.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 22 Nov 2005 09:53:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to anfänger-frage polymorphismus on Tue, 22 Nov 2005 09:53:14 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte eine Datenstuktur liste selbst schreiben und suche nach einer möglichkeit dieser Klasse eine funktion zu übergeben, so dass diese funktion<br />
für jedes Element der Liste ausgeführt wird.</p>
<p>Nochmal ausführlicher:<br />
ich habe:</p>
<pre><code class="language-cpp">class Liste{
 Node *next;
 Node *prev;
}
</code></pre>
<p>und könnte dieser Klasse jetzt natürlich für jede Aufgabe eine Funktion hinzufügen: void forEachPrint(), void forEachPlus1(), forEachSquare(), usw, usw,<br />
das scheint mir aber blöd.</p>
<p>ich hätte gerne eine Funktion die so aussieht:</p>
<pre><code>void do( hier übergebe ich funktion f)
{
  f(this);
  next-&gt;do(f)
}
</code></pre>
<p>wie geht das und kann ich im netz eine ausführliche erklärung dazu finden?</p>
<p>Liebe Grüße,<br />
Raphael</p>
]]></description><link>https://www.c-plusplus.net/forum/post/924093</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/924093</guid><dc:creator><![CDATA[raphael2]]></dc:creator><pubDate>Tue, 22 Nov 2005 09:53:14 GMT</pubDate></item><item><title><![CDATA[Reply to anfänger-frage polymorphismus on Tue, 22 Nov 2005 09:57:24 GMT]]></title><description><![CDATA[<p>Schau dir mal die Dokumentation von std::foreach() an - die macht etwas ähnliches mit STL-konformen Containern (bzw. Iteratoren).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/924101</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/924101</guid><dc:creator><![CDATA[CStoll (off)]]></dc:creator><pubDate>Tue, 22 Nov 2005 09:57:24 GMT</pubDate></item><item><title><![CDATA[Reply to anfänger-frage polymorphismus on Tue, 22 Nov 2005 11:35:10 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;list&gt;
using namespace std;

template &lt;typename T&gt;
class Liste
{
	list&lt;T&gt; m_list;

public:
	Liste()
	{
		m_list.push_back(22);
		m_list.push_back(41);
		m_list.push_back(18);
	}

	template&lt;typename TAktion&gt;
	void machBeiJedem(TAktion aktion)
	{
		for(list&lt;T&gt;::iterator iter = m_list.begin(); iter!=m_list.end(); ++iter)
			aktion(*iter);
	}
};

void ausgabe(int i) { cout &lt;&lt; i &lt;&lt; endl; }
void einsMehr(int &amp;i) { ++i; }

int main()
{
    Liste&lt;int&gt; eineListe;	

	eineListe.machBeiJedem(einsMehr);
	eineListe.machBeiJedem(ausgabe);

    cin.get();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/924165</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/924165</guid><dc:creator><![CDATA[schorsch code]]></dc:creator><pubDate>Tue, 22 Nov 2005 11:35:10 GMT</pubDate></item><item><title><![CDATA[Reply to anfänger-frage polymorphismus on Tue, 22 Nov 2005 11:39:58 GMT]]></title><description><![CDATA[<p>manche Compiler bestehen auf typename bei list&lt;T&gt;::iterator</p>
<pre><code class="language-cpp">template&lt;typename TAktion&gt;
void machBeiJedem(TAktion aktion)
{
    for(typename list&lt;T&gt;::iterator iter = m_list.begin(); iter!=m_list.end(); ++iter)
        aktion(*iter);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/924171</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/924171</guid><dc:creator><![CDATA[schorsch code]]></dc:creator><pubDate>Tue, 22 Nov 2005 11:39:58 GMT</pubDate></item><item><title><![CDATA[Reply to anfänger-frage polymorphismus on Tue, 22 Nov 2005 14:40:48 GMT]]></title><description><![CDATA[<p>Vielen Dank, genau das habe ich gesucht!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/924416</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/924416</guid><dc:creator><![CDATA[raphael2]]></dc:creator><pubDate>Tue, 22 Nov 2005 14:40:48 GMT</pubDate></item></channel></rss>