<?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[Derivec Class + virtual function problem]]></title><description><![CDATA[<p>Hallo, ich habe eine Klasse FrameworkElement:</p>
<pre><code>class FrameworkElement
{
	public:
		FrameworkElement();

                virtual void OnRender();
};
</code></pre>
<p>und zwei abgeleitete Klassen Panel und TextBlock:</p>
<pre><code>class Panel : public FrameworkElement
{
	public:
		Panel();

		std::list&lt;FrameworkElement&gt; m_Children;
		virtual void OnRender();
};

void Panel::AddChild(FrameworkElement child)
{
	m_Children.push_back(child);
}

void Panel::OnRender()
{
     for(std::list&lt;FrameworkElement&gt;::iterator it = m_Children.begin(); it != m_Children.end(); ++it)
         it-&gt;OnRender();
}
</code></pre>
<pre><code>class TextBlock : public FrameworkElement
{
	public:
		TextBlock();

		void OnRender();
};
</code></pre>
<p>erzeuge ich jetzt im Code einen TextBlock und &quot;adde&quot; diesen im Panel:</p>
<pre><code>m_pMainPanel = new Panel();
	m_pTextBlock = new TextBlock();
	m_pMainPanel-&gt;AddChild(*m_pTextBlock);
</code></pre>
<p>Dann wird jedoch die OnRender()-Funktion des FrameworkElements aufgerufen und nicht die des TextBlocks, obwohl dies doch gar nicht sein dürfte. Woran kann das liegen? Ich vermute es liegt an der list&lt;FrameworkElement&gt;.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/268343/derivec-class-virtual-function-problem</link><generator>RSS for Node</generator><lastBuildDate>Tue, 01 Sep 2026 21:04:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/268343.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 07 Jun 2010 20:13:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Derivec Class + virtual function problem on Mon, 07 Jun 2010 20:15:13 GMT]]></title><description><![CDATA[<p>Hallo, ich habe eine Klasse FrameworkElement:</p>
<pre><code>class FrameworkElement
{
	public:
		FrameworkElement();

                virtual void OnRender();
};
</code></pre>
<p>und zwei abgeleitete Klassen Panel und TextBlock:</p>
<pre><code>class Panel : public FrameworkElement
{
	public:
		Panel();

		std::list&lt;FrameworkElement&gt; m_Children;
		virtual void OnRender();
};

void Panel::AddChild(FrameworkElement child)
{
	m_Children.push_back(child);
}

void Panel::OnRender()
{
     for(std::list&lt;FrameworkElement&gt;::iterator it = m_Children.begin(); it != m_Children.end(); ++it)
         it-&gt;OnRender();
}
</code></pre>
<pre><code>class TextBlock : public FrameworkElement
{
	public:
		TextBlock();

		void OnRender();
};
</code></pre>
<p>erzeuge ich jetzt im Code einen TextBlock und &quot;adde&quot; diesen im Panel:</p>
<pre><code>m_pMainPanel = new Panel();
	m_pTextBlock = new TextBlock();
	m_pMainPanel-&gt;AddChild(*m_pTextBlock);
</code></pre>
<p>Dann wird jedoch die OnRender()-Funktion des FrameworkElements aufgerufen und nicht die des TextBlocks, obwohl dies doch gar nicht sein dürfte. Woran kann das liegen? Ich vermute es liegt an der list&lt;FrameworkElement&gt;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1908583</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1908583</guid><dc:creator><![CDATA[Student83]]></dc:creator><pubDate>Mon, 07 Jun 2010 20:15:13 GMT</pubDate></item><item><title><![CDATA[Reply to Derivec Class + virtual function problem on Mon, 07 Jun 2010 20:42:24 GMT]]></title><description><![CDATA[<p>Versuchs mal mit einer list aus Zeigern anstatt die Objekte zu kopieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1908601</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1908601</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Mon, 07 Jun 2010 20:42:24 GMT</pubDate></item><item><title><![CDATA[Reply to Derivec Class + virtual function problem on Mon, 07 Jun 2010 22:45:05 GMT]]></title><description><![CDATA[<p>Ok, habe ich soweit geändert. Die for Schleife schaut jetzt so aus:</p>
<pre><code>for(std::list&lt;FrameworkElement*&gt;::iterator it = m_Children.begin(); it != m_Children.end(); ++it)
it-&gt;OnRender();
</code></pre>
<p>Allerdings kommt an der Stelle it-&gt;OnRender() jetzt folgende Fehlermeldung:</p>
<p>'OnRender' : is not a member of 'std::_List_iterator&lt;_Mylist&gt;<br />
invalid return type 'FrameworkElement **' for overloaded 'operator -&gt;'</p>
<p>Auch<br />
&amp;it-&gt;OnRender();<br />
*it-&gt;OnRender();<br />
*it.OnRender();<br />
&amp;it.OnRender();</p>
<p>hat nicht funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1908676</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1908676</guid><dc:creator><![CDATA[Student83]]></dc:creator><pubDate>Mon, 07 Jun 2010 22:45:05 GMT</pubDate></item><item><title><![CDATA[Reply to Derivec Class + virtual function problem on Mon, 07 Jun 2010 22:47:08 GMT]]></title><description><![CDATA[<p>Priorität von -&gt; über * beachten und Klammern verwenden. Erst den Iterator dereferenzieren, dann Methode aufrufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1908679</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1908679</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Mon, 07 Jun 2010 22:47:08 GMT</pubDate></item><item><title><![CDATA[Reply to Derivec Class + virtual function problem on Mon, 07 Jun 2010 23:01:14 GMT]]></title><description><![CDATA[<p>Meinst du (*it)-&gt;OnRender(); ? Leider stürzt das Programm nun andieser Stelle ab.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1908684</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1908684</guid><dc:creator><![CDATA[Student83]]></dc:creator><pubDate>Mon, 07 Jun 2010 23:01:14 GMT</pubDate></item><item><title><![CDATA[Reply to Derivec Class + virtual function problem on Mon, 07 Jun 2010 23:05:09 GMT]]></title><description><![CDATA[<p>Geht doch, ich hatte noch was anderes getestet und nicht wieder rückgängig gemacht. Danke dir für die Hilfe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1908686</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1908686</guid><dc:creator><![CDATA[Student83]]></dc:creator><pubDate>Mon, 07 Jun 2010 23:05:09 GMT</pubDate></item></channel></rss>