<?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[Compiler-Fehler bei einfacher Vererbung]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe überhaupt gar keine Ahnung, warum folgender Code nicht compiliert. Habs mit VC 8 und g++ versucht, beide liefern denselben Fehler (&quot;'B::Init' : function does not take 1 arguments&quot;).</p>
<p>Warum nur??? Ich dachte, das sei einfach nur Vererbung. Noch einfacher geht's ja fast nicht...</p>
<pre><code class="language-cpp">#include &lt;string&gt;

class A
{
public:
    void Init(const std::string&amp; s){};
    virtual void Init(const std::string&amp; s, int a){};
};

class B : public A
{
public:
    virtual void Init(const std::string&amp; s, int a){};
};

int main()
{
    B b;
    b.Init(&quot;Hallo!&quot;);
    return 0;
}
</code></pre>
<p>Tausend Dank,<br />
Felix</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/182538/compiler-fehler-bei-einfacher-vererbung</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 23:55:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/182538.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 26 May 2007 09:12:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Compiler-Fehler bei einfacher Vererbung on Sat, 26 May 2007 09:12:03 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe überhaupt gar keine Ahnung, warum folgender Code nicht compiliert. Habs mit VC 8 und g++ versucht, beide liefern denselben Fehler (&quot;'B::Init' : function does not take 1 arguments&quot;).</p>
<p>Warum nur??? Ich dachte, das sei einfach nur Vererbung. Noch einfacher geht's ja fast nicht...</p>
<pre><code class="language-cpp">#include &lt;string&gt;

class A
{
public:
    void Init(const std::string&amp; s){};
    virtual void Init(const std::string&amp; s, int a){};
};

class B : public A
{
public:
    virtual void Init(const std::string&amp; s, int a){};
};

int main()
{
    B b;
    b.Init(&quot;Hallo!&quot;);
    return 0;
}
</code></pre>
<p>Tausend Dank,<br />
Felix</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1292567</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1292567</guid><dc:creator><![CDATA[FelixManke]]></dc:creator><pubDate>Sat, 26 May 2007 09:12:03 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler-Fehler bei einfacher Vererbung on Sat, 26 May 2007 09:16:51 GMT]]></title><description><![CDATA[<p>b.Init muss einen Integer als 2. paramerter bekommen<br />
bei g++ geht das:</p>
<pre><code class="language-cpp">#include &lt;string&gt;

class A
{
public:
    void Init(const std::string&amp; s){};
    virtual void Init(const std::string&amp; s, int a){};
};

class B : public A
{
public:
    virtual void Init(const std::string&amp; s, int a){};
};

int main()
{
    B b;
    b.Init(&quot;Hallo!&quot;, 1);
    return 0;
}
</code></pre>
<p>steht sogar im funktionskopf. hat nichts mit vererbung zu tuen<br />
ich verordne dir als strafe 15 minuten tutorial lesn xD</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1292569</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1292569</guid><dc:creator><![CDATA[blub2]]></dc:creator><pubDate>Sat, 26 May 2007 09:16:51 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler-Fehler bei einfacher Vererbung on Sat, 26 May 2007 09:38:49 GMT]]></title><description><![CDATA[<p>Eine Deklaration verdeckt <em>jede</em> andere Deklaration gleichen Namens in einem äußeren Scope bzw. einer Basisklasse. Das Überschreiben der virtuellen Init-Funktion ist ebenfalls eine solche Deklaration und verdeckt die geerbte Init-Funktion aus A. Mehrere Varianten zur Abhilfe sind möglich:<br />
1. durch qualifizierten Aufruf:</p>
<pre><code class="language-cpp">int main()
{
    B b;
    b.A::Init(&quot;Hallo!&quot;);
    return 0;
}
</code></pre>
<p>2. durch Deklaration einer enstprechenden Überladung in B:</p>
<pre><code class="language-cpp">class B : public A
{
public:
    void Init(const std::string&amp; s){ return A::Init(s); }
    virtual void Init(const std::string&amp; s, int a){}
};
</code></pre>
<p>3. mittels using-Deklaration:</p>
<pre><code class="language-cpp">class B : public A
{
public:
    using A::Init;
    virtual void Init(const std::string&amp; s, int a){}
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1292573</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1292573</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 26 May 2007 09:38:49 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler-Fehler bei einfacher Vererbung on Sat, 26 May 2007 09:33:06 GMT]]></title><description><![CDATA[<p>ABER: B erbt von A, ergo B erbt auch die Methoden von A. Und da A::Init(const std::string&amp; s) definiert ist, sollte man auch b.Init(&quot;Hallo!&quot;) aufrufen können, oder???</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1292576</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1292576</guid><dc:creator><![CDATA[FelixManke]]></dc:creator><pubDate>Sat, 26 May 2007 09:33:06 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler-Fehler bei einfacher Vererbung on Sat, 26 May 2007 09:46:43 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>Eine Deklaration verdeckt <em>jede</em> andere Deklaration gleichen Namens in einem äußeren Scope bzw. einer Basisklasse.</p>
</blockquote>
<p>Ist das mit NAME ernst gemeint?!?! Oder Signatur?? Wobei -- da ich den Fehler bekomme, ist's wohl der Name...</p>
<p>Das finde ich aber sehr sehr verwirrend. Methoden sind normalerweise bei C++/Java/C#/... durch die <strong>Signatur</strong> (also Name UND Parameterliste) und nicht den Namen allein unterschieden.</p>
<p>Cheers,<br />
Felix</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1292581</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1292581</guid><dc:creator><![CDATA[FelixManke]]></dc:creator><pubDate>Sat, 26 May 2007 09:46:43 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler-Fehler bei einfacher Vererbung on Sat, 26 May 2007 10:01:07 GMT]]></title><description><![CDATA[<p>Also das wäre mir auch neu, das der Name verdeckt wird. Ich müsste das für C++ auch noch mal speziell ausprobieren (meine tägliche Java-Arbeit sagt mir, das der Name nicht verdeckt wird!).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1292589</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1292589</guid><dc:creator><![CDATA[Artchi]]></dc:creator><pubDate>Sat, 26 May 2007 10:01:07 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler-Fehler bei einfacher Vererbung on Sat, 26 May 2007 10:01:36 GMT]]></title><description><![CDATA[<p>FelixManke schrieb:</p>
<blockquote>
<p>Das finde ich aber sehr sehr verwirrend. Methoden sind normalerweise bei C++/Java/C#/... durch die <strong>Signatur</strong> (also Name UND Parameterliste) und nicht den Namen allein unterschieden.</p>
</blockquote>
<p>Das ist auch richtig. Worauf du dich beziehst ist die Überladungsauflösung, wenn eine Funktion mehrere Überladungen hat. Bevor diese aber stattfinden kann, müssen aber erst einmal alle Überladungen, die in Frage kommen, gefunden werden. Dieser Vorgang (name lookup) berücksichtigt an sich nur den Namen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1292590</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1292590</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 26 May 2007 10:01:36 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler-Fehler bei einfacher Vererbung on Sat, 26 May 2007 10:09:14 GMT]]></title><description><![CDATA[<p>Artchi schrieb:</p>
<blockquote>
<p>Also das wäre mir auch neu, das der Name verdeckt wird. Ich müsste das für C++ auch noch mal speziell ausprobieren (meine tägliche Java-Arbeit sagt mir, das der Name nicht verdeckt wird!).</p>
</blockquote>
<p>Weil die Funktion nur überschrieben wird? Das hat mich auch etwas unsicher gemacht, aber der Standard macht da keinen Unterschied. Eine große Rolle dürfte das kaum spielen, denn in der Regel werden virtuelle Funktionen wohl nicht überladen werden (oder man weicht auf des Template Pattern aus). D.h. Variante 4:</p>
<pre><code class="language-cpp">class A
{
public:
    void Init(const std::string&amp; s){};
    void Init(const std::string&amp; s, int a) { return Init_impl(s,a); }
private:
    virtual void Init_impl(const std::string&amp; s, int a){};
};

class B : public A
{
private:
    virtual void Init_impl(const std::string&amp; s, int a){};
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1292593</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1292593</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 26 May 2007 10:09:14 GMT</pubDate></item><item><title><![CDATA[Reply to Compiler-Fehler bei einfacher Vererbung on Sat, 26 May 2007 10:07:22 GMT]]></title><description><![CDATA[<p>camper hat Recht. Man kann es es sehen, wenn wann den Namen Init(const string&amp;) in Init2(const string&amp;) ändert. Dann ist der Compiler zufrieden. Nicht leicht verständlich, aber der C++-Standard sagt es so:</p>
<blockquote>
<p>The declaration of a member in a derived class (clause 10) hides the declaration of a member of<br />
a base class of the same name; see 10.2.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1292594</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1292594</guid><dc:creator><![CDATA[UBr]]></dc:creator><pubDate>Sat, 26 May 2007 10:07:22 GMT</pubDate></item></channel></rss>