<?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[Ueberladungskonstruktor &amp;amp;&amp;amp; Veerbung]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>stehe widermal vor einem Problem...<br />
Kann mir jemand helfen wie ich diese Fehlermeldung beheben kann!!</p>
<p>Wie sollte die Deklaration in der Header Datei gegliedert seien, damit ich im main programm ohne probleme der instanz werte via parameter übergeben kann... (Zeile 49 und Zeile 66)</p>
<p>Fehlermedlung des Compilers:</p>
<pre><code>&quot;d:\visualstudio2012\vorlesungen\vererb_ueberlad_kopier_stand_konstruktor\vererb_ueberlad_kopier_stand_konstruktor\vererb_ueberlad_kopier_stand_konstruktor.cpp(18): error C2661: 'CEnkel::CEnkel': Keine überladene Funktion akzeptiert 2 Argumente
1&gt;d:\visualstudio2012\vorlesungen\vererb_ueberlad_kopier_stand_konstruktor\vererb_ueberlad_kopier_stand_konstruktor\vererb_ueberlad_kopier_stand_konstruktor.cpp(19): error C2661: 'CSohn::CSohn': Keine überladene Funktion akzeptiert 3 Argumente
========== Erstellen: 0 erfolgreich, 1 fehlerhaft, 0 aktuell, 0 übersprungen ==========
&quot;
</code></pre>
<pre><code>#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;

using namespace std;

class COpa {

private: 

		//Attribute
	int x;

public:

		//STANDARDKONSTRUKTOR
		//
	COpa();
		//KOPIERKONSTRUKTOR
		//
	COpa(const COpa&amp; ); 

		//UEBERLADUNGSKONSTRUKTOR
		//Wird nur aufgerufen, wenn im Hauptprogramm der Instanz ein Wert uberegeben wird!!!!!
	COpa(int); 

		//Methode zur Ausgabe des Attributes der Klasse COpa
		//
	void foo(); 

};

// Klasse COpa wird an Klasse CSohn vererbt!!!

class CSohn:public COpa {     //Klasse CSohn wurde von der Klasse COpa geerbt!!!!

private:
	int y;

public:

		//STANDARDKONSTRUKTOR	
		//
	CSohn();
		//KOPIERKONSTRUKTOR
		//
	CSohn(const CSohn&amp; );
		//UEBERLADUNGSKONSTRUKTOR
		//
	CSohn(int, int):COpa(int); 
		//AUSGABE
		//
	void foo();

};

class CEnkel : public CSohn {
private:
	int z;
public:

		//Konstruktor
	CEnkel();
		//Kopierkonstruktor
	CEnkel(const CEnkel&amp;);
		//Überladenerkonstruktor
	CEnkel(int,int,int):CSohn(int,int); 
		//Ausgabe
	void foo();

};
</code></pre>
<pre><code>//Quelldatei zum Projekt Vererb_Ueberlad_Kopier_Stand_Konstruktor
//29.10.2013

#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &quot;header.h&quot;

using namespace std;

	//STANDARDKONSTRUKTOR
	//
	COpa::COpa()  {

		x = 1;
	}

	//KOPIERKONSTRUKTOR
	//
	COpa::COpa(const COpa&amp; original) {

		x = original.x;			// Hier in diesem Fall, wird sozusagen, die &quot;Kopie&quot; vom Original im Attribut x erstellt/ueberwiesen!!!
	}

	//UEBERLADUNGSKONSTRUKTOR
	//Wird nur aufgerufen, wenn im Hauptprogramm der Instanz ein Wert uberegeben wird!!!!!
	COpa::COpa(int neu) {

		x = neu;
	}

	//Ausgabe von Copa
	void COpa:: foo() {

		cout &lt;&lt; &quot;x: &quot; &lt;&lt; x &lt;&lt; endl;
	}

	//VERERBUNG
	//KLASSE CSohn(...)

	//STANDARDKONSTRUKTOR	
	//
	CSohn::CSohn() {
		y = 1;
	}

	//KOPIERKONSTRUKTOR
	//
	CSohn::CSohn(const CSohn&amp; original) {

		y = original.y;
	}

	//UEBERLADUNGSKONSTRUKTOR
	//

	CSohn::CSohn(int x, int y):COpa(x) {
		this-&gt;y = y;
	}

	//AUSGABE
	//
	void CSohn:: foo() {
		cout &lt;&lt; &quot;y: &quot; &lt;&lt; y;
	}

	//Konstruktor
	CEnkel::CEnkel() {
		z=1;
	}

	//Kopierkonstruktor
	CEnkel::CEnkel(const CEnkel&amp; original) {

		z = original.z;
	}

	//Überladenerkonstruktor
	CEnkel::CEnkel(int x,int y,int z):CSohn(x,y){

		this-&gt;z = z;

	}
	//Ausgabe
	void CEnkel:: foo(){
		cout &lt;&lt; &quot;z: &quot; &lt;&lt; z &lt;&lt; endl;
	}
</code></pre>
<pre><code>#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &quot;header.h&quot;

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{

	COpa   irgendwas(5);
	CSohn  irgendwas_neues(3,4); 
	CEnkel  irgendwas_anderes_neues(2,4,2); 

	irgendwas_anderes_neues.foo();

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/321259/ueberladungskonstruktor-amp-amp-veerbung</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Jul 2026 17:30:11 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/321259.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 29 Oct 2013 23:04:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ueberladungskonstruktor &amp;amp;&amp;amp; Veerbung on Tue, 29 Oct 2013 23:26:38 GMT]]></title><description><![CDATA[<p>Hi Leute,</p>
<p>stehe widermal vor einem Problem...<br />
Kann mir jemand helfen wie ich diese Fehlermeldung beheben kann!!</p>
<p>Wie sollte die Deklaration in der Header Datei gegliedert seien, damit ich im main programm ohne probleme der instanz werte via parameter übergeben kann... (Zeile 49 und Zeile 66)</p>
<p>Fehlermedlung des Compilers:</p>
<pre><code>&quot;d:\visualstudio2012\vorlesungen\vererb_ueberlad_kopier_stand_konstruktor\vererb_ueberlad_kopier_stand_konstruktor\vererb_ueberlad_kopier_stand_konstruktor.cpp(18): error C2661: 'CEnkel::CEnkel': Keine überladene Funktion akzeptiert 2 Argumente
1&gt;d:\visualstudio2012\vorlesungen\vererb_ueberlad_kopier_stand_konstruktor\vererb_ueberlad_kopier_stand_konstruktor\vererb_ueberlad_kopier_stand_konstruktor.cpp(19): error C2661: 'CSohn::CSohn': Keine überladene Funktion akzeptiert 3 Argumente
========== Erstellen: 0 erfolgreich, 1 fehlerhaft, 0 aktuell, 0 übersprungen ==========
&quot;
</code></pre>
<pre><code>#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;

using namespace std;

class COpa {

private: 

		//Attribute
	int x;

public:

		//STANDARDKONSTRUKTOR
		//
	COpa();
		//KOPIERKONSTRUKTOR
		//
	COpa(const COpa&amp; ); 

		//UEBERLADUNGSKONSTRUKTOR
		//Wird nur aufgerufen, wenn im Hauptprogramm der Instanz ein Wert uberegeben wird!!!!!
	COpa(int); 

		//Methode zur Ausgabe des Attributes der Klasse COpa
		//
	void foo(); 

};

// Klasse COpa wird an Klasse CSohn vererbt!!!

class CSohn:public COpa {     //Klasse CSohn wurde von der Klasse COpa geerbt!!!!

private:
	int y;

public:

		//STANDARDKONSTRUKTOR	
		//
	CSohn();
		//KOPIERKONSTRUKTOR
		//
	CSohn(const CSohn&amp; );
		//UEBERLADUNGSKONSTRUKTOR
		//
	CSohn(int, int):COpa(int); 
		//AUSGABE
		//
	void foo();

};

class CEnkel : public CSohn {
private:
	int z;
public:

		//Konstruktor
	CEnkel();
		//Kopierkonstruktor
	CEnkel(const CEnkel&amp;);
		//Überladenerkonstruktor
	CEnkel(int,int,int):CSohn(int,int); 
		//Ausgabe
	void foo();

};
</code></pre>
<pre><code>//Quelldatei zum Projekt Vererb_Ueberlad_Kopier_Stand_Konstruktor
//29.10.2013

#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &quot;header.h&quot;

using namespace std;

	//STANDARDKONSTRUKTOR
	//
	COpa::COpa()  {

		x = 1;
	}

	//KOPIERKONSTRUKTOR
	//
	COpa::COpa(const COpa&amp; original) {

		x = original.x;			// Hier in diesem Fall, wird sozusagen, die &quot;Kopie&quot; vom Original im Attribut x erstellt/ueberwiesen!!!
	}

	//UEBERLADUNGSKONSTRUKTOR
	//Wird nur aufgerufen, wenn im Hauptprogramm der Instanz ein Wert uberegeben wird!!!!!
	COpa::COpa(int neu) {

		x = neu;
	}

	//Ausgabe von Copa
	void COpa:: foo() {

		cout &lt;&lt; &quot;x: &quot; &lt;&lt; x &lt;&lt; endl;
	}

	//VERERBUNG
	//KLASSE CSohn(...)

	//STANDARDKONSTRUKTOR	
	//
	CSohn::CSohn() {
		y = 1;
	}

	//KOPIERKONSTRUKTOR
	//
	CSohn::CSohn(const CSohn&amp; original) {

		y = original.y;
	}

	//UEBERLADUNGSKONSTRUKTOR
	//

	CSohn::CSohn(int x, int y):COpa(x) {
		this-&gt;y = y;
	}

	//AUSGABE
	//
	void CSohn:: foo() {
		cout &lt;&lt; &quot;y: &quot; &lt;&lt; y;
	}

	//Konstruktor
	CEnkel::CEnkel() {
		z=1;
	}

	//Kopierkonstruktor
	CEnkel::CEnkel(const CEnkel&amp; original) {

		z = original.z;
	}

	//Überladenerkonstruktor
	CEnkel::CEnkel(int x,int y,int z):CSohn(x,y){

		this-&gt;z = z;

	}
	//Ausgabe
	void CEnkel:: foo(){
		cout &lt;&lt; &quot;z: &quot; &lt;&lt; z &lt;&lt; endl;
	}
</code></pre>
<pre><code>#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &quot;header.h&quot;

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{

	COpa   irgendwas(5);
	CSohn  irgendwas_neues(3,4); 
	CEnkel  irgendwas_anderes_neues(2,4,2); 

	irgendwas_anderes_neues.foo();

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2363797</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2363797</guid><dc:creator><![CDATA[ramazancinardere]]></dc:creator><pubDate>Tue, 29 Oct 2013 23:26:38 GMT</pubDate></item><item><title><![CDATA[Reply to Ueberladungskonstruktor &amp;amp;&amp;amp; Veerbung on Wed, 30 Oct 2013 07:43:34 GMT]]></title><description><![CDATA[<p>Hab jetzt grad keinen Compiler zur Hand, aber das sieht für mich etwas fremd aus (z.B. &quot;CSohn(int, int):COpa(int);&quot; in der Header-Datei. Lass doch mal das &quot;:COpa(int)&quot; weg, hast Du doch schon!<br />
Gruß Helmut</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2363816</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2363816</guid><dc:creator><![CDATA[Helmut.Jakoby]]></dc:creator><pubDate>Wed, 30 Oct 2013 07:43:34 GMT</pubDate></item><item><title><![CDATA[Reply to Ueberladungskonstruktor &amp;amp;&amp;amp; Veerbung on Wed, 30 Oct 2013 09:32:59 GMT]]></title><description><![CDATA[<p>Vielen Dank für die Antwort. Du hast recht, ich habe dass &quot;:Copa(int)&quot;, vom Code CSohn(int, int):COpa(int);, weggelassen; es funktiort. Supe 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="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2363828</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2363828</guid><dc:creator><![CDATA[ramazancinardere]]></dc:creator><pubDate>Wed, 30 Oct 2013 09:32:59 GMT</pubDate></item><item><title><![CDATA[Reply to Ueberladungskonstruktor &amp;amp;&amp;amp; Veerbung on Wed, 30 Oct 2013 10:10:02 GMT]]></title><description><![CDATA[<p>Hmm, ich glaube hier gibt es ein kleines Verständnisproblem, was Vererbung angeht.</p>
<p>Kommt dynamische Vererbung (ist das mit virtual) zum Einsatz, muss immer ein virtueller Destruktor vorhanden sein. Du bekommmst sonst Probleme beim Abbau von Objekten.</p>
<p>Ich gebe mal ein allgemeines Beispiel, dass die Probleme aufklären sollte. Ich versuche es auch gleichzeitig anhand eines praktischen Beispiels zu zeigen.</p>
<p>Hier wäre die Definition, also Vector.hxx (ich gehöre zu den Leuten, die .cxx und .hxx verwenden)</p>
<pre><code>#include &lt;string&gt;

// --- Vector2 ---
class Vector2 {
public:
  // --- Vector2: public data structures ---
  float x;
  float y;

  // --- constructors and deconstructors ---
  Vector2();
  Vector2(const float&amp; xx, const float&amp; yy);
  Vector2(const Vector2&amp; rhs);
  virtual ~Vector2();

  // --- Vector2: base operators ---
  Vector2&amp; operator=(const Vector2&amp; rhs);
  bool operator==(const Vector2&amp; rhs) const;
  bool operator!=(const Vector2&amp; rhs) const;

  // --- Vector2: default methods ---
  virtual std::string string() const;
};

// --- Vector3 ---
class Vector3 : public Vector2 {
public:
  // --- Vector3: publioc data structures ---
  float z;

  // --- Vector3: constructors and deconstructors ---
  Vector3();
  Vector3(const Vector2&amp; vec, const float&amp;&amp; zz = 0.0);
  Vector3(const float&amp; xx, const float&amp;&amp; yy, const float&amp;&amp; zz);
  Vector3(const Vector3&amp; rhs);
  virtual ~Vector3();

  // --- Vector3: base operators ---
  Vector3&amp; operator=(const Vector3&amp; rhs);
  bool operator==(const Vector3&amp; rhs) const;
  bool operator!=(const Vector3&amp; rhs) const;

  // --- Vector3: public methods ---
  virtual std::string string() const;
};
</code></pre>
<p>Und hier kommt die Implementierung, also Vector.cxx ...</p>
<pre><code>#include &lt;sstream&gt;
#include &quot;Vector.hxx&quot;

// --- Vector2: constructors and deconstructors ---
Vector2::Vector2()
: x(0.0), y(0.0)
{
}

Vector2::Vector2(const float&amp; xx, const float&amp; yy)
: x(xx), y(yy)
{
}

Vector2::Vector2(const Vector2&amp; rhs)
: x(rhs.x), y(rhs.y)
{
}

Vector2::~Vector2()
{
}

// --- Vector2: base operators ---
Vector2&amp; Vector2::operator=(const Vector2&amp; rhs)
{
  if (this != &amp;rhs)
  {
    x = rhs.x;
    y = rhs.y;
  }

  return *this;
}

bool Vector2::operator==(const Vector2&amp; rhs) const
{
  return x == rhs.x &amp;&amp;
         y == rhs.y;
}

bool Vector2::operator!=(const Vector2&amp; rhs) const
{
  return !(*this == rhs);
}

// --- Vector2: public methods ---
std::string Vector2::string() const
{
  std::stringstream result;

  result &lt;&lt; x &lt;&lt; &quot;, &quot;
         &lt;&lt; y;

  return result.str();
}

// --- Vector3: constructors and deconstructors ---
Vector3::Vector3()
: Vector2(0.0, 0.0), z(0.0)
{
}

Vector3::Vector3(const Vector2&amp; vec, const float&amp; zz)
: Vector2(vec), z(zz)
{
}

Vector3::Vector3(const float&amp; xx, const float&amp; yy, const float&amp; zz)
: Vector2(xx, yy), z(zz)
{
}

Vector3::Vector3(const Vector3&amp; rhs)
: Vector2(rhs.x, rhs.y), z(rhs.z)
{
}

Vector3::~Vector3()
{
}

// --- Vector3: base operators ---
Vector3&amp; Vector3::operator=(const Vector3&amp; rhs)
{
  if (this != &amp;rhs)
  {
    Vector2::operator=(rhs);
    z = rhs.z;
  }

  return *this;
}

bool Vector3::operator==(const Vector3&amp; rhs) const
{
  return Vector2::operator==(rhs) &amp;&amp;
         z == rhs.z;
}

bool Vector3::operator!=(const Vector3&amp; rhs) const
{
  return !(*this == rhs);
}

// --- Vector3: public methods ---
std::string Vector3::string() const
{
  std::stringstream result;

  result &lt;&lt; Vector2::string() &lt;&lt; &quot;, &quot;
         &lt;&lt; z;

  return result.str();
}
</code></pre>
<p>Das sollte eine halbwegs elegante Implementierung sein, die in Sachen Vererbung alles beachtet, was es zu beachten gibt. Und ich hoffe mal, dass sich kein Typo eingeschlichen hat. Das sollte man problemlos 1:1 verwenden können.</p>
<p>Wenns Fragen gibt, dann nur zu <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2363831</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2363831</guid><dc:creator><![CDATA[Akiko]]></dc:creator><pubDate>Wed, 30 Oct 2013 10:10:02 GMT</pubDate></item></channel></rss>