<?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[Sicher stellen, dass abgeleitete Methode verwendet wird?]]></title><description><![CDATA[<p>Hallo!<br />
Ich habe in etwa folgende Sache vor:</p>
<pre><code>CBase** array=new CBase*[n];
array[0]=new CChild();
array[1]=new CChild2();
//etc...
for(int i=0;i&lt;n;i++)
array[i]-&gt;doSomething();//Bitte nur bei Bedarf CBase::doSomething()
</code></pre>
<p>Wie stelle ich sicher, dass doSomething() die Methoden der abgeleiteten Klasse benutzt? z.B. gibt es CChild::doSomething(), aber nicht CChild2::doSomething(), wo dann natürlich CBase::doSomething() aufgerufen werden muss. Im Moment würde ja immer CBase::doSomething aufgerufen werden, oder?<br />
Gibt es einen cast, der mir automatisch die unterste Ebene castet, also automatisch auf CChild oder CChild2?<br />
Danke!<br />
Viele Grüße<br />
Sören</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/191108/sicher-stellen-dass-abgeleitete-methode-verwendet-wird</link><generator>RSS for Node</generator><lastBuildDate>Fri, 25 Sep 2026 21:48:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/191108.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 30 Aug 2007 09:29:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Sicher stellen, dass abgeleitete Methode verwendet wird? on Thu, 30 Aug 2007 09:29:31 GMT]]></title><description><![CDATA[<p>Hallo!<br />
Ich habe in etwa folgende Sache vor:</p>
<pre><code>CBase** array=new CBase*[n];
array[0]=new CChild();
array[1]=new CChild2();
//etc...
for(int i=0;i&lt;n;i++)
array[i]-&gt;doSomething();//Bitte nur bei Bedarf CBase::doSomething()
</code></pre>
<p>Wie stelle ich sicher, dass doSomething() die Methoden der abgeleiteten Klasse benutzt? z.B. gibt es CChild::doSomething(), aber nicht CChild2::doSomething(), wo dann natürlich CBase::doSomething() aufgerufen werden muss. Im Moment würde ja immer CBase::doSomething aufgerufen werden, oder?<br />
Gibt es einen cast, der mir automatisch die unterste Ebene castet, also automatisch auf CChild oder CChild2?<br />
Danke!<br />
Viele Grüße<br />
Sören</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1355185</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1355185</guid><dc:creator><![CDATA[soerenP]]></dc:creator><pubDate>Thu, 30 Aug 2007 09:29:31 GMT</pubDate></item><item><title><![CDATA[Reply to Sicher stellen, dass abgeleitete Methode verwendet wird? on Thu, 30 Aug 2007 09:34:38 GMT]]></title><description><![CDATA[<p>virtual</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1355187</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1355187</guid><dc:creator><![CDATA[Polymorphie]]></dc:creator><pubDate>Thu, 30 Aug 2007 09:34:38 GMT</pubDate></item><item><title><![CDATA[Reply to Sicher stellen, dass abgeleitete Methode verwendet wird? on Thu, 30 Aug 2007 09:35:20 GMT]]></title><description><![CDATA[<p>die methoden virtuel machen</p>
<p>je nach objekt tpy wird die entsprechende methoden aufgerufen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1355188</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1355188</guid><dc:creator><![CDATA[BorisDieKlinge]]></dc:creator><pubDate>Thu, 30 Aug 2007 09:35:20 GMT</pubDate></item><item><title><![CDATA[Reply to Sicher stellen, dass abgeleitete Methode verwendet wird? on Thu, 30 Aug 2007 09:40:07 GMT]]></title><description><![CDATA[<p>Also, so?:</p>
<pre><code>class CBase
{
...
   virtual void doSomething()
}
class CChild:public CBase
{
... 
    virtual void doSomething()
}
</code></pre>
<p>... und es funzt?<br />
Vielen Dank!<br />
Sören</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1355192</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1355192</guid><dc:creator><![CDATA[soerenP]]></dc:creator><pubDate>Thu, 30 Aug 2007 09:40:07 GMT</pubDate></item><item><title><![CDATA[Reply to Sicher stellen, dass abgeleitete Methode verwendet wird? on Thu, 30 Aug 2007 13:38:38 GMT]]></title><description><![CDATA[<p>Das &quot;sicherste&quot;:</p>
<pre><code class="language-cpp">class foo
{
public:
    inline void bar()
    {
        bar_impl();
    }
private:
    virtual void bar_impl()
    {
        printf(&quot;foo\n&quot;);
    }
};

class foo2 : public foo
{
private:
    virtual void bar_impl() // bar_impl überschreiben...
    {
        printf(&quot;foo2\n&quot;);
    }
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1355368</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1355368</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Thu, 30 Aug 2007 13:38:38 GMT</pubDate></item><item><title><![CDATA[Reply to Sicher stellen, dass abgeleitete Methode verwendet wird? on Thu, 30 Aug 2007 15:57:54 GMT]]></title><description><![CDATA[<p>kein printf in c++ <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_down"
      title=":-1:"
      alt="👎"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1355476</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1355476</guid><dc:creator><![CDATA[Krux]]></dc:creator><pubDate>Thu, 30 Aug 2007 15:57:54 GMT</pubDate></item><item><title><![CDATA[Reply to Sicher stellen, dass abgeleitete Methode verwendet wird? on Thu, 30 Aug 2007 16:14:16 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>Das &quot;sicherste&quot;:</p>
</blockquote>
<p>nicht sicherer oder unsicherer. Der Vorteil liegt eher darin, dass wir Dinge mit verschiedenen Funktionen (Deklaration eines polymorphen Interfaces [naja... polymorphes Verhalten an sich lässt sich in C++ nicht deklarieren...] in Form von bar() bzw. ein Implementationsdetail in Form einer virtuellen Funktion) getrennt haben,</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1355496</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1355496</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 30 Aug 2007 16:14:16 GMT</pubDate></item><item><title><![CDATA[Reply to Sicher stellen, dass abgeleitete Methode verwendet wird? on Thu, 30 Aug 2007 19:05:45 GMT]]></title><description><![CDATA[<p>&quot;Sicher&quot; deswegen weil dadurch von aussen keiner mehr die Möglichkeit hat die Version einer bestimmten Klasse aufzurufen, da</p>
<ol>
<li>Nur die &quot;oberste&quot; Klasse in der Hierarchie die &quot;bar&quot; Funktion hat und</li>
<li>Die &quot;bar_impl&quot; Funktion überall private ist.<br />
Dadurch kann ich nichtmehr &quot;p-&gt;fooN::bar_impl();&quot; schreiben und damit die falsche Funktion erwischen, und wenn ich &quot;p-&gt;fooN::bar();&quot; schreibe macht es nix, weil es nur eine Implementierung gibt, die dann immer virtual die eigentliche Funktion aufruft.</li>
</ol>
<p>&quot;Sicher&quot; also in dem Sinn dass man dadurch &quot;misuse&quot; von aussen verhindern kann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1355625</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1355625</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Thu, 30 Aug 2007 19:05:45 GMT</pubDate></item><item><title><![CDATA[Reply to Sicher stellen, dass abgeleitete Methode verwendet wird? on Thu, 30 Aug 2007 20:12:01 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>&quot;Sicher&quot; deswegen weil dadurch von aussen keiner mehr die Möglichkeit hat die Version einer bestimmten Klasse aufzurufen</p>
</blockquote>
<p>Naja, aber so was passiert doch nicht aus Versehen.</p>
<p>...</p>
<p><a href="http://www.gotw.ca/publications/mill18.htm" rel="nofollow">http://www.gotw.ca/publications/mill18.htm</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1355681</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1355681</guid><dc:creator><![CDATA[finix]]></dc:creator><pubDate>Thu, 30 Aug 2007 20:12:01 GMT</pubDate></item><item><title><![CDATA[Reply to Sicher stellen, dass abgeleitete Methode verwendet wird? on Fri, 31 Aug 2007 10:06:17 GMT]]></title><description><![CDATA[<p>und bitte mach den destructor der basisklasse virtual. siehe scott meyers</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1355926</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1355926</guid><dc:creator><![CDATA[ConfusedGuy]]></dc:creator><pubDate>Fri, 31 Aug 2007 10:06:17 GMT</pubDate></item><item><title><![CDATA[Reply to Sicher stellen, dass abgeleitete Methode verwendet wird? on Fri, 31 Aug 2007 13:51:55 GMT]]></title><description><![CDATA[<p>finix schrieb:</p>
<blockquote>
<p>hustbaer schrieb:</p>
<blockquote>
<p>&quot;Sicher&quot; deswegen weil dadurch von aussen keiner mehr die Möglichkeit hat die Version einer bestimmten Klasse aufzurufen</p>
</blockquote>
<p>Naja, aber so was passiert doch nicht aus Versehen.</p>
<p>...</p>
<p><a href="http://www.gotw.ca/publications/mill18.htm" rel="nofollow">http://www.gotw.ca/publications/mill18.htm</a></p>
</blockquote>
<p>Threadtitel schrieb:</p>
<blockquote>
<p>Sicher stellen, dass abgeleitete Methode verwendet wird?</p>
</blockquote>
<p>???<br />
Huh?<br />
Was Du woll?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1356111</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1356111</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Fri, 31 Aug 2007 13:51:55 GMT</pubDate></item></channel></rss>