<?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[Vererbung&#x2F;Mehrfachvererbung Konstruktoren]]></title><description><![CDATA[<p>Hallo <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Ich schlage mich gerade ein bisschen mit Vererbung und Mehrfachvererbung rum. Es funktioniert soweit ganz gut, bis auf die Sache mit den Konstruktoren.</p>
<p>Ich hab die Klassen Girokonto und Festgeldkonto. Diese erben beide von Oberklasse Konto. Konto ist abstrakt und hat einen Standartkonstruktor ohne Argumente. Girokonto und Festgeldkonto haben Argumente.<br />
Nun hab ich die Klasse Flexkonto hinzugefügt, die von Giro und Festgeldkonto erbt. Nun müssen ja die Konstruktoren der Oberklasse aufgerufen werden, nur funktioniert das nicht so ganz. Irgendwas mach ich wohl falsch.</p>
<p>Ich bezieh ich mal nur auf die konstruktoren, weil der Rest ja funzt:<br />
Header Girokonto:</p>
<pre><code>Girokonto(double, string);
</code></pre>
<p>Cpp:</p>
<pre><code>Girokonto::Girokonto(double zahl, string name) {
    saldo = zahl;
    waehrung = name;
    ueberziehungslinie=-2000;
    negativzins=1.09;
    positivzins=1.002;
}
</code></pre>
<p>Header Festgeld:</p>
<pre><code>Festgeldkonto(double, string);
</code></pre>
<p>Cpp:</p>
<pre><code>Festgeldkonto::Festgeldkonto(double zahl, string name) {
    saldo = zahl;
    waehrung = name;
}
</code></pre>
<p>Und die Klasse Flexkonto:</p>
<pre><code>Flexkonto(double, string);
Flexkonto(const Flexkonto&amp; orig); //Hier bekomme ich die selbe Fehlermeldung wie beim Konstruktor
</code></pre>
<pre><code>Flexkonto::Flexkonto(double zahl, string name){
    Girokonto(zahl, name);
    Festgeldkonto(zahl, name);
    Girokonto::saldo=zahl;
    Girokonto::waehrung=name;
}

Flexkonto::Flexkonto(const Flexkonto&amp; orig) {
}
</code></pre>
<p>Die Fehlermeldung ist &quot;No matching function for call to Girokonto::girokonto()&quot;<br />
&quot;No matching function for call to Festgeldkonto::Festgeldkonto()&quot;</p>
<p>Beim Kopierkonstruktor bekomme ich diese Fehlermeldung auch.<br />
Wie mache ich das denn genau mit den Konstruktoren?</p>
<p>Vielen dank schonmal für Hilfe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/332378/vererbung-mehrfachvererbung-konstruktoren</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 03:47:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/332378.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 26 Apr 2015 09:38:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Vererbung&#x2F;Mehrfachvererbung Konstruktoren on Sun, 26 Apr 2015 09:38:36 GMT]]></title><description><![CDATA[<p>Hallo <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Ich schlage mich gerade ein bisschen mit Vererbung und Mehrfachvererbung rum. Es funktioniert soweit ganz gut, bis auf die Sache mit den Konstruktoren.</p>
<p>Ich hab die Klassen Girokonto und Festgeldkonto. Diese erben beide von Oberklasse Konto. Konto ist abstrakt und hat einen Standartkonstruktor ohne Argumente. Girokonto und Festgeldkonto haben Argumente.<br />
Nun hab ich die Klasse Flexkonto hinzugefügt, die von Giro und Festgeldkonto erbt. Nun müssen ja die Konstruktoren der Oberklasse aufgerufen werden, nur funktioniert das nicht so ganz. Irgendwas mach ich wohl falsch.</p>
<p>Ich bezieh ich mal nur auf die konstruktoren, weil der Rest ja funzt:<br />
Header Girokonto:</p>
<pre><code>Girokonto(double, string);
</code></pre>
<p>Cpp:</p>
<pre><code>Girokonto::Girokonto(double zahl, string name) {
    saldo = zahl;
    waehrung = name;
    ueberziehungslinie=-2000;
    negativzins=1.09;
    positivzins=1.002;
}
</code></pre>
<p>Header Festgeld:</p>
<pre><code>Festgeldkonto(double, string);
</code></pre>
<p>Cpp:</p>
<pre><code>Festgeldkonto::Festgeldkonto(double zahl, string name) {
    saldo = zahl;
    waehrung = name;
}
</code></pre>
<p>Und die Klasse Flexkonto:</p>
<pre><code>Flexkonto(double, string);
Flexkonto(const Flexkonto&amp; orig); //Hier bekomme ich die selbe Fehlermeldung wie beim Konstruktor
</code></pre>
<pre><code>Flexkonto::Flexkonto(double zahl, string name){
    Girokonto(zahl, name);
    Festgeldkonto(zahl, name);
    Girokonto::saldo=zahl;
    Girokonto::waehrung=name;
}

Flexkonto::Flexkonto(const Flexkonto&amp; orig) {
}
</code></pre>
<p>Die Fehlermeldung ist &quot;No matching function for call to Girokonto::girokonto()&quot;<br />
&quot;No matching function for call to Festgeldkonto::Festgeldkonto()&quot;</p>
<p>Beim Kopierkonstruktor bekomme ich diese Fehlermeldung auch.<br />
Wie mache ich das denn genau mit den Konstruktoren?</p>
<p>Vielen dank schonmal für Hilfe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2451587</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451587</guid><dc:creator><![CDATA[Cabooze]]></dc:creator><pubDate>Sun, 26 Apr 2015 09:38:36 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung&#x2F;Mehrfachvererbung Konstruktoren on Sun, 26 Apr 2015 11:30:01 GMT]]></title><description><![CDATA[<p>Du musst eine Initialisierungsliste benutzen:<br />
Nicht:</p>
<pre><code>Flexkonto::Flexkonto(double zahl, string name){
    Girokonto(zahl, name);
    Festgeldkonto(zahl, name);
    Girokonto::saldo=zahl;
    Girokonto::waehrung=name;
}
</code></pre>
<p>sondern:</p>
<pre><code>Flexkonto::Flexkonto(double zahl, string name) : Girokonto(zahl, name), Festgeldkonto(zahl, name){}
</code></pre>
<p>Ähnlich bei dem Kopierkonstruktor, wobei Du da das Problem hast, dass Dein Parameter orig ja zweimal zahl und name besitzt, nämlich einmal aus der Oberklasse Girokonto und einmal aus der Oberklasse Festgeldkonto; ich weiß nicht aus dem Ärmel, wie Du das qualifizieren musst, damit der Compiler das schluckt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2451591</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451591</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Sun, 26 Apr 2015 11:30:01 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung&#x2F;Mehrfachvererbung Konstruktoren on Sun, 26 Apr 2015 13:42:23 GMT]]></title><description><![CDATA[<p>Danke <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> Funktioniert. Hätte nicht gedacht dass es unbedingt eine Initialisierungsliste sein muss.</p>
<p>Hat noch jemand eine Idee beim Kopierkonstruktor? Wenn nicht lass ich ihn einfach weg. Nur falls jemand das noch wissen sollte</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2451606</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451606</guid><dc:creator><![CDATA[Cabooze]]></dc:creator><pubDate>Sun, 26 Apr 2015 13:42:23 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung&#x2F;Mehrfachvererbung Konstruktoren on Sun, 26 Apr 2015 14:11:38 GMT]]></title><description><![CDATA[<p>Ach ich hab seit gestern auch noch eine Sache.</p>
<p>Ich versuche das Programm mit Polymorphie zu implementieren. Also hab ich n Array aus Pointern erstellt mit denen sich dann neue Konten hinzufügen lassen.</p>
<pre><code>Konto * kp[100];

                cout &lt;&lt; &quot;Was für ein Konto möchten sie anlegen? 1. Giro 2. Festgeld 3. Flex? &quot;, cin &gt;&gt; wahl;
                cout &lt;&lt; &quot;Währung festlegen&quot;, cin &gt;&gt; waehr;
                cout &lt;&lt; &quot;Startsaldo festlegen&quot;, cin &gt;&gt; sald;
                if(wahl==1)
                    kp[n]=new Girokonto(sald,waehr);
                else if(wahl==2)
                    kp[n]=new Festgeldkonto(sald,waehr);
                else if(wahl==3)
                    kp[n]=new Flexkonto(sald,waehr); //Fehlermeldung
                else
                    cout &lt;&lt; &quot;Ungültige Eingabe!&quot; &lt;&lt;endl;
</code></pre>
<p>Sobald ich eine neue Instanz von Flexkonto anlegen will bekomme ich die Meldung: Konto is an amgibuous base of Flexkonto.<br />
Mit den anderen beiden Klassen funktioniert es.<br />
Was muss ich machen um das zu beheben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2451609</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451609</guid><dc:creator><![CDATA[Cabooze]]></dc:creator><pubDate>Sun, 26 Apr 2015 14:11:38 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung&#x2F;Mehrfachvererbung Konstruktoren on Sun, 26 Apr 2015 14:18:18 GMT]]></title><description><![CDATA[<p>Das sagt dir, dass dein Design schlecht ist. Du hast zwei Konten &quot;nebeneinander&quot;. Welches soll denn jetzt benutzt werden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2451610</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451610</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sun, 26 Apr 2015 14:18:18 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung&#x2F;Mehrfachvererbung Konstruktoren on Mon, 27 Apr 2015 08:38:08 GMT]]></title><description><![CDATA[<p>Okay habs jetzt. Hab es mit virtuellen Klassen realisiert. Funktioniert.<br />
Ist das worauf du hinauswolltest manni66 oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2451654</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451654</guid><dc:creator><![CDATA[Cabooze]]></dc:creator><pubDate>Mon, 27 Apr 2015 08:38:08 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung&#x2F;Mehrfachvererbung Konstruktoren on Mon, 27 Apr 2015 09:02:05 GMT]]></title><description><![CDATA[<p>Cabooze schrieb:</p>
<blockquote>
<p>Okay habs jetzt. Hab es mit virtuellen Klassen realisiert. Funktioniert.</p>
</blockquote>
<p>Wirklich?</p>
<p>Cabooze schrieb:</p>
<blockquote>
<p>Ist das worauf du hinauswolltest manni66 oder?</p>
</blockquote>
<p>Nein. Das mag zwar dein aktuelles Problem lösen, aber bist du jetzt wirklich weiter?<br />
Dein Angaben sind sehr wenig konkret, aber schlussendlich läuft es wohl auf das heraus:</p>
<pre><code class="language-cpp">struct K
{
        virtual void buchen(double v) = 0;
};

struct A : virtual K
{
        void buchen(double v){};
};

struct B : virtual K
{
        void buchen(double v){};
};

struct C : A, B
{
};

int main()
{
        C aC;

        aC.buchen(2.2);
}
</code></pre>
<p>Das wird nicht übersetzt. Welches &quot;buchen&quot; soll denn jetzt genommen werden?</p>
<p>BTW, ich habe auch double verwendet. Das ist für Geldbeträge aber eher ungünstig. Warum wird hier im Forum einmal wöchentlich erklärt =&gt; Suchfunktion</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2451658</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2451658</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Mon, 27 Apr 2015 09:02:05 GMT</pubDate></item></channel></rss>