<?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[[gelöst] Vererbungshierarchie und Verdeckung]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe folgenden Beispielcode:</p>
<pre><code class="language-cpp">#include &lt;cstdio&gt;

 class Useless{};

 class IntInterface
 {
 	public:
 		virtual void Do(int&amp; a)	= 0;
 };

 class UselessInterface
 {
 	public:
 		virtual void Do(Useless&amp; a)	= 0;
 };

 class NoLeaf : public IntInterface
 {
 public:
 	virtual void Do(int&amp; test) 
 	{
 		printf(&quot;int&quot;);
 	};
 };

 class Leaf : public NoLeaf, public UselessInterface
 {
 public:

 	//virtual void Do(int&amp; a)
 	//{
 	//	NoLeaf::Do(a);
 	//}

 	virtual void Do(Useless&amp; a) 
 	{
 		printf(&quot;Useless&quot;);
 	}	
 };

int main( void )
{
	Leaf a;
	Useless c;
	int b = 0;
	a.Do(c);
	a.Do(b); // &lt;-- hier krachts, mit einem  error C2664
	/* Begin adding your custom code here */
	return 0;
}
</code></pre>
<p>Ich verstehe nicht, warum es bei <strong><a href="http://a.Do" rel="nofollow">a.Do</a>(b)</strong> kracht, da er die Funktion doch durch die Ableitung von NoLeaf kennen müsste.</p>
<p>Kann mir jemand erklären warum das passiert?</p>
<p>Danke<br />
Tobi</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/270915/gelöst-vererbungshierarchie-und-verdeckung</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 21:15:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/270915.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 20 Jul 2010 10:16:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [gelöst] Vererbungshierarchie und Verdeckung on Tue, 20 Jul 2010 12:01:22 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe folgenden Beispielcode:</p>
<pre><code class="language-cpp">#include &lt;cstdio&gt;

 class Useless{};

 class IntInterface
 {
 	public:
 		virtual void Do(int&amp; a)	= 0;
 };

 class UselessInterface
 {
 	public:
 		virtual void Do(Useless&amp; a)	= 0;
 };

 class NoLeaf : public IntInterface
 {
 public:
 	virtual void Do(int&amp; test) 
 	{
 		printf(&quot;int&quot;);
 	};
 };

 class Leaf : public NoLeaf, public UselessInterface
 {
 public:

 	//virtual void Do(int&amp; a)
 	//{
 	//	NoLeaf::Do(a);
 	//}

 	virtual void Do(Useless&amp; a) 
 	{
 		printf(&quot;Useless&quot;);
 	}	
 };

int main( void )
{
	Leaf a;
	Useless c;
	int b = 0;
	a.Do(c);
	a.Do(b); // &lt;-- hier krachts, mit einem  error C2664
	/* Begin adding your custom code here */
	return 0;
}
</code></pre>
<p>Ich verstehe nicht, warum es bei <strong><a href="http://a.Do" rel="nofollow">a.Do</a>(b)</strong> kracht, da er die Funktion doch durch die Ableitung von NoLeaf kennen müsste.</p>
<p>Kann mir jemand erklären warum das passiert?</p>
<p>Danke<br />
Tobi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1929052</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929052</guid><dc:creator><![CDATA[Tobias Gerg]]></dc:creator><pubDate>Tue, 20 Jul 2010 12:01:22 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Vererbungshierarchie und Verdeckung on Tue, 20 Jul 2010 11:46:59 GMT]]></title><description><![CDATA[<p>Du greifst aber nicht auf <strong>Leaf::NoLeaf.Do()</strong> zu sondern auf <strong>Leaf:: Do()</strong><br />
Und da wird ein <strong>Useless&amp;</strong> erwartet.<br />
So greifst Du auf die Vererbung zu, wenn ich Dein Problem richtig verstanden habe.</p>
<pre><code class="language-cpp">#include &lt;cstdio&gt; 

class Useless
 {

 }; 

 class IntInterface 
 { 
     public: 
         virtual void DoNL(int&amp; a)    = 0; 
 }; 

 class UselessInterface 
 { 
     public: 
         virtual void Do(Useless&amp; a)    = 0; 
 }; 

 class NoLeaf : public IntInterface 
 { 
 public: 
     virtual void DoNL(int&amp; test)
     { 
         printf(&quot;int&quot;); 
     }; 
 }; 

 class Leaf : public NoLeaf, public UselessInterface 
 { 
 public: 

     //virtual void Do(int&amp; a) 
     //{ 
     //    NoLeaf:o(a); 
     //} 

     virtual void Do(Useless&amp; a) 
     { 
         printf(&quot;Useless&quot;); 
     }    
 }; 

int main( void ) 
{ 
	Leaf a;
	Useless c; 
    int b = 0; 
    a.Do(c);
	a.DoNL(b); // &lt;-- hier krachts, mit einem  error C2664 
    /* Begin adding your custom code here */ 
    return 0; 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1929107</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929107</guid><dc:creator><![CDATA[Doug_HH]]></dc:creator><pubDate>Tue, 20 Jul 2010 11:46:59 GMT</pubDate></item><item><title><![CDATA[Reply to [gelöst] Vererbungshierarchie und Verdeckung on Tue, 20 Jul 2010 12:02:29 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>danke für die Antwort, aber bei dem Code ist es ja genau der Witz, dass ich gleiche Funktionsnamen aber verschiedene Signaturen habe.</p>
<p>Allerdings habe ich gerade im Meyers (3 Auflage) die Regel 33 gelesen. Das Problem ist eben die Namensverdeckung.</p>
<p>So wie ich die Regel verstanden haben verdeckt das Do in Leaf dass Do in NoLeaf. Es spielt dabei keine Rolle, dass die Signaturen der Funktion unterschiedlich sind.</p>
<p>Daher muss entweder ein Weiterleitungsfunktion (wie der auskommentierte Teil im Code) verwenden oder ein</p>
<pre><code class="language-cpp">...
using NoLeaf::Do();
</code></pre>
<p>Damit ist das Thema für mich gelöst.</p>
<p>Greets<br />
Tobi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1929115</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1929115</guid><dc:creator><![CDATA[Tobias Gerg]]></dc:creator><pubDate>Tue, 20 Jul 2010 12:02:29 GMT</pubDate></item></channel></rss>