<?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[SOLVED - Vordefinieren von Klassen, Vererbung und Konstruktor]]></title><description><![CDATA[<p>Hallo.</p>
<p>Ich habe ein paar Klassen, die in Wirklichkeit weit umfangreicher sind. Bei der Vererbung und dem Konstruktor der Abgeleiteten Klasse bekomme ich Probleme.</p>
<p>Mein Test Programm sieht wie folgt aus:</p>
<p>ClassPreDefintion.h</p>
<pre><code>#define CLASS_PRE_DEFINITION_H

class CDomain {
    protected:
	char* Name;

    public:
	CDomain();
};

class CBoundary {
    protected:
	char* Name;
	CDomain* D;

    public:
	CBoundary(CDomain* pD);
};

class CInlet : CBoundary {
    private:
	double NormalVelocity;

    public:
	CInlet(CDomain* pD) : CBoundary(pD); /*Fehlermeldung: Expected a&quot;{&quot;*/
};
</code></pre>
<p>Functions.h</p>
<pre><code>#define CLASS_FUNCTIONS_H

CDomain::CDomain() {
	Name = nullptr;
}

CBoundary::CBoundary(CDomain* pD) {
	this-&gt;D = pD;
	Name = nullptr;
}

CInlet::CInlet(CDomain* pD) {

}
</code></pre>
<p>main.cpp</p>
<pre><code>#ifndef CLASS_PRE_DEFINITION_H
	#include &quot;ClassPreDefinition.h&quot;
#endif

#ifndef CLASS_FUNCTIONS_H
	#include &quot;Functions.h&quot;
#endif

int main() {
	return 0;
}
</code></pre>
<p>Ich möchte die Klassen gerne vordefinieren und den jeweiligen Konstruktor in einem separaten Headerfile beschreiben. Bei normalen Funktionen und bei Konstruktoren von einfachen Klassen ist das kein Problem. Das geht doch sicher auch bei abgeleiteten Klassen, oder?</p>
<p>Vielen Dank im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/340539/solved-vordefinieren-von-klassen-vererbung-und-konstruktor</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 22:01:25 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/340539.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 14 Nov 2016 20:54:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to SOLVED - Vordefinieren von Klassen, Vererbung und Konstruktor on Mon, 14 Nov 2016 21:42:46 GMT]]></title><description><![CDATA[<p>Hallo.</p>
<p>Ich habe ein paar Klassen, die in Wirklichkeit weit umfangreicher sind. Bei der Vererbung und dem Konstruktor der Abgeleiteten Klasse bekomme ich Probleme.</p>
<p>Mein Test Programm sieht wie folgt aus:</p>
<p>ClassPreDefintion.h</p>
<pre><code>#define CLASS_PRE_DEFINITION_H

class CDomain {
    protected:
	char* Name;

    public:
	CDomain();
};

class CBoundary {
    protected:
	char* Name;
	CDomain* D;

    public:
	CBoundary(CDomain* pD);
};

class CInlet : CBoundary {
    private:
	double NormalVelocity;

    public:
	CInlet(CDomain* pD) : CBoundary(pD); /*Fehlermeldung: Expected a&quot;{&quot;*/
};
</code></pre>
<p>Functions.h</p>
<pre><code>#define CLASS_FUNCTIONS_H

CDomain::CDomain() {
	Name = nullptr;
}

CBoundary::CBoundary(CDomain* pD) {
	this-&gt;D = pD;
	Name = nullptr;
}

CInlet::CInlet(CDomain* pD) {

}
</code></pre>
<p>main.cpp</p>
<pre><code>#ifndef CLASS_PRE_DEFINITION_H
	#include &quot;ClassPreDefinition.h&quot;
#endif

#ifndef CLASS_FUNCTIONS_H
	#include &quot;Functions.h&quot;
#endif

int main() {
	return 0;
}
</code></pre>
<p>Ich möchte die Klassen gerne vordefinieren und den jeweiligen Konstruktor in einem separaten Headerfile beschreiben. Bei normalen Funktionen und bei Konstruktoren von einfachen Klassen ist das kein Problem. Das geht doch sicher auch bei abgeleiteten Klassen, oder?</p>
<p>Vielen Dank im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2515343</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2515343</guid><dc:creator><![CDATA[CJens]]></dc:creator><pubDate>Mon, 14 Nov 2016 21:42:46 GMT</pubDate></item><item><title><![CDATA[Reply to SOLVED - Vordefinieren von Klassen, Vererbung und Konstruktor on Mon, 14 Nov 2016 21:10:31 GMT]]></title><description><![CDATA[<p>Die Definitionen gehören nicht in ein Headerfile, sondern in ein cpp-File, Du brauchst also (ich bleibe mal teilweise bei Deiner seltsamen Namensgebung):</p>
<p>ClassPreDefintion.h<br />
ClassPreDefintion.cpp<br />
main.cpp</p>
<p>Dann gehört die Initialisierungsliste (CInlet) nicht zur Deklaration, sondern zur Definition, also in diesem Fall in die cpp-Datei.</p>
<p>Und die Geschichte mit den Include-Guards solltest Du Dir auch ganz dringend noch mal ansehen, die gehören ins Headerfile ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2515345</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2515345</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Mon, 14 Nov 2016 21:10:31 GMT</pubDate></item><item><title><![CDATA[Reply to SOLVED - Vordefinieren von Klassen, Vererbung und Konstruktor on Mon, 14 Nov 2016 21:26:03 GMT]]></title><description><![CDATA[<p>Ich dachte, ein Headerfile wird einfach in das main.cpp kopiert.<br />
Wie binde ich dann das zweite cpp File mit ein?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2515347</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2515347</guid><dc:creator><![CDATA[CJens]]></dc:creator><pubDate>Mon, 14 Nov 2016 21:26:03 GMT</pubDate></item><item><title><![CDATA[Reply to SOLVED - Vordefinieren von Klassen, Vererbung und Konstruktor on Mon, 14 Nov 2016 21:42:23 GMT]]></title><description><![CDATA[<p>Ok, hab es hin bekommen. Funktioniert wie folgt:</p>
<p>ClassPreDefinition.h</p>
<pre><code>#define CLASS_PRE_DEFINITION_H

class CDomain {
private:
	char* Name;

public:
	CDomain();
};

class CBoundary {
protected:
	char* Name;
	CDomain* D;

public:
	CBoundary(CDomain* pD);
};

class CInlet : public CBoundary {
private:
	double NormalVelocity;

public:
	CInlet(CDomain* pD);
};
</code></pre>
<p>Function.h</p>
<pre><code>#define CLASS_FUNCTIONS_H

CDomain::CDomain() {
	Name = nullptr;
}

CBoundary::CBoundary(CDomain* pD) {
	this-&gt;D = pD;
	Name = nullptr;
	printf(&quot;CBoundary constructor!\n&quot;);
}

CInlet::CInlet(CDomain* pD) : CBoundary(pD){
	this-&gt;D = pD;
	printf(&quot;CInlet constructor!\n&quot;);
}
</code></pre>
<p>main.cpp</p>
<pre><code>#ifndef STDIO_H
	#define STDIO_H
	#include &lt;stdio.h&gt;
#endif

#ifndef CLASS_PRE_DEFINITION_H
	#include &quot;ClassPreDefinition.h&quot;
#endif

#ifndef CLASS_FUNCTIONS_H
	#include &quot;Functions.h&quot;
#endif

int main() {
	CDomain* D = new CDomain();
	CBoundary* B = new CBoundary(D);
	CInlet* In = new CInlet(D);

	getchar();
	return 0;
}
</code></pre>
<p>Results wie erwartet:<br />
*<br />
CBoundary constructor!<br />
CBoundary constructor!<br />
CInlet constructor!<br />
*</p>
<p>Mich würde aber trotzdem mal interessieren, was an diesem Ansatz falsch ist - also, die Einwendung von Belli.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2515348</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2515348</guid><dc:creator><![CDATA[CJens]]></dc:creator><pubDate>Mon, 14 Nov 2016 21:42:23 GMT</pubDate></item><item><title><![CDATA[Reply to SOLVED - Vordefinieren von Klassen, Vererbung und Konstruktor on Mon, 14 Nov 2016 22:45:16 GMT]]></title><description><![CDATA[<p>CJens schrieb:</p>
<blockquote>
<p>Ich dachte, ein Headerfile wird einfach in das main.cpp kopiert.<br />
Wie binde ich dann das zweite cpp File mit ein?</p>
</blockquote>
<p>Ein Headerfile wird dahin kopiert (via #include), wo man es benötigt.<br />
Und cpp-Files werden kompiliert und danach zusammengelinkt.<br />
Wie das konkret gemacht wird, hängt davon ab, wie Du Deine Programme baust: Durch Kommandozeilenbefehle oder mittels einer IDE ...<br />
In der Kommandozeile zB.</p>
<p>cl /EHsc main.cpp ClassPreDefintion.cpp (wenn Du Visual Studio benutzt) oder<br />
g++ main.cpp ClassPreDefintion.cpp (Wenn Du g++ benutzt)</p>
<p>Und wie gesagt: Include-Guards gehören nicht in ein cpp-File.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2515357</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2515357</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Mon, 14 Nov 2016 22:45:16 GMT</pubDate></item></channel></rss>