<?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 klappt nicht]]></title><description><![CDATA[<p>Hi, es geht um eine simple vererbung. Die Basisklasse besteht aus den großen 3 und zwei funktionen. Die Kindklasse nur aus den großen 3.</p>
<p>Fehlermeldung: No matching function for call to hallo::hallo ()...<br />
In der Fehlermeldung wird dann auf die Kindklasse verwiesen.</p>
<pre><code>#include &lt;iostream&gt;

using namespace std;

class hallo {

	protected:

	int id;
	int rakete;
	int bombe;

	public:
			explicit hallo (int ID) : id (ID) {
		cout &lt;&lt; &quot;Konstruktor, Id: &quot; &lt;&lt; id &lt;&lt; endl;
		rakete = 5;
		bombe = 10;
	}	
	~hallo () {
		cout &lt;&lt; &quot;Virtual Konstruktor, id: &quot; &lt;&lt; id &lt;&lt; endl;
	}	
	hallo (const hallo&amp; rhs) {
		cout &lt;&lt; &quot;Virtual Kopierkonstruktor, Id: &quot; &lt;&lt; id &lt;&lt; endl;
	}	
    virtual void zeigedaten () {
    	cout &lt;&lt; &quot;Aktuelle Raketen und Bombenanzahl\n&quot;
    	        &quot;Bomben: &quot; &lt;&lt; bombe &lt;&lt; endl &lt;&lt; &quot;Raketen: &quot; &lt;&lt; rakete &lt;&lt; endl;    	        
    }

    void waffen () {
    	bombe--;
    	rakete--;
    	cout &lt;&lt; &quot;Waffen wurden abgefeuert\n&quot;;
    }
};
class tschuess : public hallo {		

	tschuess () {
		cout &lt;&lt; &quot;Tschuesskonstruktor&quot;;
	}		
	~tschuess () {
		cout &lt;&lt; &quot;Tschuess geloescht&quot;;
	}	
	tschuess (const tschuess&amp; rhs) {
		cout &lt;&lt; &quot;Kopier Tschuesskonstruktor&quot;;
		}
};
int main () {

	hallo halloe(1);
	tschuess ts(1);

	halloe.waffen();
	halloe.zeigedaten();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/322160/vererbung-klappt-nicht</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Jul 2026 08:07:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/322160.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 09 Dec 2013 12:54:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Vererbung klappt nicht on Mon, 09 Dec 2013 12:54:09 GMT]]></title><description><![CDATA[<p>Hi, es geht um eine simple vererbung. Die Basisklasse besteht aus den großen 3 und zwei funktionen. Die Kindklasse nur aus den großen 3.</p>
<p>Fehlermeldung: No matching function for call to hallo::hallo ()...<br />
In der Fehlermeldung wird dann auf die Kindklasse verwiesen.</p>
<pre><code>#include &lt;iostream&gt;

using namespace std;

class hallo {

	protected:

	int id;
	int rakete;
	int bombe;

	public:
			explicit hallo (int ID) : id (ID) {
		cout &lt;&lt; &quot;Konstruktor, Id: &quot; &lt;&lt; id &lt;&lt; endl;
		rakete = 5;
		bombe = 10;
	}	
	~hallo () {
		cout &lt;&lt; &quot;Virtual Konstruktor, id: &quot; &lt;&lt; id &lt;&lt; endl;
	}	
	hallo (const hallo&amp; rhs) {
		cout &lt;&lt; &quot;Virtual Kopierkonstruktor, Id: &quot; &lt;&lt; id &lt;&lt; endl;
	}	
    virtual void zeigedaten () {
    	cout &lt;&lt; &quot;Aktuelle Raketen und Bombenanzahl\n&quot;
    	        &quot;Bomben: &quot; &lt;&lt; bombe &lt;&lt; endl &lt;&lt; &quot;Raketen: &quot; &lt;&lt; rakete &lt;&lt; endl;    	        
    }

    void waffen () {
    	bombe--;
    	rakete--;
    	cout &lt;&lt; &quot;Waffen wurden abgefeuert\n&quot;;
    }
};
class tschuess : public hallo {		

	tschuess () {
		cout &lt;&lt; &quot;Tschuesskonstruktor&quot;;
	}		
	~tschuess () {
		cout &lt;&lt; &quot;Tschuess geloescht&quot;;
	}	
	tschuess (const tschuess&amp; rhs) {
		cout &lt;&lt; &quot;Kopier Tschuesskonstruktor&quot;;
		}
};
int main () {

	hallo halloe(1);
	tschuess ts(1);

	halloe.waffen();
	halloe.zeigedaten();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2370727</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2370727</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Mon, 09 Dec 2013 12:54:09 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung klappt nicht on Mon, 09 Dec 2013 12:56:37 GMT]]></title><description><![CDATA[<p>Wenn Du nichts weiter in der Initialisier-Liste des abgelittenen Konstruktors angibst, wird die Basisklasse Default-Konstruiert. Aber Deine Basisklasse hat keinen Default-Konstruktor.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2370728</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2370728</guid><dc:creator><![CDATA[decimad]]></dc:creator><pubDate>Mon, 09 Dec 2013 12:56:37 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung klappt nicht on Mon, 09 Dec 2013 12:58:21 GMT]]></title><description><![CDATA[<p>Was ist so schwierig daran, die Meldung zu kopieren? Kein Mensch will deine halbgaren Umschreibungen lesen!</p>
<p>Du hast keinen Defaultkonstruktor in hallo. Das wird in der Meldung wohl auch so stehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2370729</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2370729</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Mon, 09 Dec 2013 12:58:21 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung klappt nicht on Mon, 09 Dec 2013 13:12:59 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">~hallo () { 
         cout &lt;&lt; &quot;Virtual Konstruktor, id: &quot; &lt;&lt; id &lt;&lt; endl; 
     }   
     hallo (const hallo&amp; rhs) { 
         cout &lt;&lt; &quot;Virtual Kopierkonstruktor, Id: &quot; &lt;&lt; id &lt;&lt; endl; 
     }
</code></pre>
<p>Konstruktoren können nicht virtuell sein.<br />
Und überdenk mal deine Benamsung (&quot;hallo&quot;, &quot;tschuess&quot;, &quot;waffen&quot; - WTF?).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2370731</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2370731</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 09 Dec 2013 13:12:59 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung klappt nicht on Mon, 09 Dec 2013 13:50:25 GMT]]></title><description><![CDATA[<p>kamelkacke schrieb:</p>
<blockquote>
<p>Die Basisklasse besteht aus den großen 3</p>
</blockquote>
<p>Nö...zumindest nicht in dem von dir geposteten Code.</p>
<p>Und zu dem was Hustbaer schon meinte:<br />
Wolltest du vielleicht 'virtueller Destruktor schreiben'?<br />
Dann mach ihn auch virtuell. Wäre ja richtig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2370738</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2370738</guid><dc:creator><![CDATA[Jockelx]]></dc:creator><pubDate>Mon, 09 Dec 2013 13:50:25 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung klappt nicht on Mon, 09 Dec 2013 14:44:09 GMT]]></title><description><![CDATA[<p>Also ein Konstruktor kann nicht virtuell sein, aber ein destruktor?<br />
Ansonsten was ist eine initialisierungsliste. Der Inhalt des Konstruktors oder die deklarationszeile mit dem parametern? Ich hab beides geändert und bekomme trotzdem den selben fehler:</p>
<p>/data/data/com.n0n3m4.droidc/files/temp.c: In constructor 'tschuess::tschuess(int)':<br />
/data/data/com.n0n3m4.droidc/files/temp.c:51:45: error: no matching function for call to 'hallo::hallo()'<br />
explicit tschuess (int kacke) : shit (kacke) {<br />
^<br />
compilation terminated due to -Wfatal-errors.</p>
<p>Die Änderungen:</p>
<pre><code>class tschuess : public hallo {

	private:

	int test;	
	bool fuck;	
	int shit;

	public:

	explicit tschuess (int kacke) : shit (kacke) {
		cout &lt;&lt; &quot;Tschuesskonstruktor&quot;;
		test = 5;
		fuck = true;
		cout &lt;&lt; id;
	}

	~tschuess () {
		cout &lt;&lt; &quot;Tschuess geloescht&quot;;
	}

	tschuess (const tschuess&amp; rhs) {
		cout &lt;&lt; &quot;Kopier Tschuesskonstruktor&quot;;
		}

		void zeigedaten () {
			cout &lt;&lt; &quot;Abgeleitet zeigedaten&quot;;}
};
</code></pre>
<p>Ps sry für die benamung, werde in zukunft drauf achten</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2370749</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2370749</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Mon, 09 Dec 2013 14:44:09 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung klappt nicht on Mon, 09 Dec 2013 14:43:57 GMT]]></title><description><![CDATA[<p>Der Fehler wird auch drin bleiben, bis du</p>
<ol>
<li>einen Defaultkonstruktor für &quot;hallo&quot; schreibst</li>
</ol>
<p>oder</p>
<ol start="2">
<li>den einzigen existierenden Konstruktor von &quot;hallo&quot; aufrufst</li>
</ol>
]]></description><link>https://www.c-plusplus.net/forum/post/2370750</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2370750</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Mon, 09 Dec 2013 14:43:57 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung klappt nicht on Mon, 09 Dec 2013 14:44:49 GMT]]></title><description><![CDATA[<p>ja hallo, gehirn einschalten bitte:</p>
<p>decimad schrieb:</p>
<blockquote>
<p>Wenn Du nichts weiter in der Initialisier-Liste des abgelittenen Konstruktors angibst, wird die Basisklasse Default-Konstruiert. Aber Deine Basisklasse hat keinen Default-Konstruktor.</p>
</blockquote>
<p>das bedeutet, dass du in allen konstruktoren von allen abgeleiteten klassen den konstruktor der basisklasse explizit aufrufen musst.</p>
<p>und ich kann hustbaer nur zustimmen, was sind das wieder für bezeichner? wem hilft sowas weiter?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2370751</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2370751</guid><dc:creator><![CDATA[arKot]]></dc:creator><pubDate>Mon, 09 Dec 2013 14:44:49 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung klappt nicht on Mon, 09 Dec 2013 14:59:46 GMT]]></title><description><![CDATA[<p>Ok, danke leute.</p>
<p>@ felix: die zweite option verstehe ich nicht. Soll der hallo konstruktor in tschuess eingebaut werden? Bzw der konstruktor soll abgeleitet werden(sofern ich richtig verstanden habe), aber wie?</p>
<p>Ach ja, dass es keine virtuellen Konstruktoren gibt weiss ich, aber virtuelle destruktoren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2370757</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2370757</guid><dc:creator><![CDATA[kamelkacke]]></dc:creator><pubDate>Mon, 09 Dec 2013 14:59:46 GMT</pubDate></item><item><title><![CDATA[Reply to Vererbung klappt nicht on Mon, 09 Dec 2013 15:15:37 GMT]]></title><description><![CDATA[<p>kamelkacke schrieb:</p>
<blockquote>
<p>Ach ja, dass es keine virtuellen Konstruktoren gibt weiss ich, aber virtuelle destruktoren?</p>
</blockquote>
<p>Virtuelle Destruktoren gibt es, virtuelle Konstruktoren hingegen nicht. Das hat den Grund, das eines von beiden sinnvoll ist, das andere Unsinn. Wann und wie sollte jemals ein virtueller Konstruktor aufgerufen werden? Man kann schließlich unmöglich einen Basisklassenzeiger auf ein nicht existerendes Objekt haben. Der ganze Vorgang der Konstruktion eines Objekts impliziert, dass man schon weiß, was für ein Objekt es ist<sup>*</sup>.</p>
<p><sup>*</sup>: Ich rede hier von der C++-Ebene, nicht von höheren Abstraktionsstufen, wie einem factory pattern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2370766</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2370766</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 09 Dec 2013 15:15:37 GMT</pubDate></item></channel></rss>