<?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[[C++] Klassen]]></title><description><![CDATA[<p>Hallo!</p>
<p>Edit: Ich entschuldige mich dafür, dass mein Code so lange ist. Ich habe jetzt vesucht ihn so viel wie möglich zu kürzen.</p>
<p>Im folgenden Code versuche ich drei Klassen zu Erstellen &quot;atom&quot; &quot;molecule&quot; und &quot;material&quot;.</p>
<p>molecule soll friend von atom sein, und material abgeleitet von molecule.</p>
<p>Die ersten beiden Klassen habe ich erstellt, bei &quot;material&quot; bekomme ich aber kryptische Error Meldungen.</p>
<p>Ich würde mich über jede Hilfe freuen!</p>
<pre><code>#include&lt;iostream&gt;
#include&lt;string&gt;
#include&lt;fstream&gt;
#include&lt;cstdio&gt;
#include&lt;cmath&gt;
#include&lt;locale&gt;
#include&lt;iomanip&gt;

using namespace std;

class atom
{
	friend class molecule;

	private:
		string Element;
		int Ordnungszahl;
		double Atommasse;

	public:	

		atom(string Name, int Z, double m):Element(Name),Ordnungszahl(Z),Atommasse(m){}

		~atom(){};
};

class molecule
{
	private:
		atom Atomart_1;
		atom Atomart_2;
		string Summenformel;
		int Anzahl_1, Anzahl_2;
		char a,b;
		double M;

	public:
		molecule(atom E_1, atom E_2, int A_1, int A_2):
					Atomart_1(E_1), Atomart_2(E_2), Anzahl_1(A_1), Anzahl_2(A_2)
		{
			M=Anzahl_1*Atomart_1.Atommasse+Anzahl_2*Atomart_2.Atommasse;
			char g=Anzahl_1+48;
			char h=Anzahl_2+48;
			Summenformel=Atomart_1.Element+g +Atomart_2.Element+ h;
		};

		~molecule(){};
};

class material:public molecule
{
	private:
		double Schmelzpunkt, Siedepunkt, Temperatur;
		string Aggregatzustand;
		molecule Molecule;

	public:
		material(molecule Mo, double Smp, double Sdp):
					Molecule(Mo), Schmelzpunkt(Smp), Siedepunkt(Sdp){}

		void show2()
		{		
			cout&lt;&lt;&quot;Der Schmelzpunkt von &quot;&lt;&lt;Molecule&lt;&lt;&quot; liegt bei &quot;&lt;&lt;Schmelzpunkt
				 &lt;&lt;&quot; K, und der Siedepunkt bei &quot;&lt;&lt;Siedepunkt&lt;&lt;&quot; K.&quot; &lt;&lt;endl;
		};

	~material(){}
};

int main()
{
	atom Wasserstoff(&quot;H&quot;, 1, 1.00794);

	atom Sauerstoff(&quot;O&quot;, 8, 15.9994);

	molecule H2O(Wasserstoff, Sauerstoff, 2, 1);

	material Wasser(H2O, 273.15, 373.15);
	Wasser.show2(); 

	return 0;
}
</code></pre>
<p>Der Kompiler spuckt folgende Error Meldungen aus</p>
<p>Test.cpp: In constructor ‘material::material(molecule, double, double)’:<br />
Test.cpp:55: warning: ‘material::Molecule’ will be initialized after<br />
Test.cpp:53: warning: ‘double material::Schmelzpunkt’<br />
Test.cpp:58: warning: when initialized here<br />
Test.cpp:59: error: no matching function for call to ‘molecule::molecule()’<br />
Test.cpp:38: note: candidates are: molecule::molecule(atom, atom, int, int)<br />
Test.cpp:28: note: molecule::molecule(const molecule&amp;)<br />
Test.cpp: In member function ‘void material::show2()’:<br />
Test.cpp:63: error: no match for ‘operator&lt;&lt;’ in ‘std::operator&lt;&lt; [with _Traits = std::char_traits&lt;char&gt;](((std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;)(&amp; std::cout)), ((const char*)&quot;Der Schmelzpunkt von &quot;)) &lt;&lt; ((material*)this)-&gt;material::Molecule’<br />
/usr/include/c++/4.2.1/ostream:112: note: candidates are: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp; (<em>)(std::basic_ostream&lt;_CharT, _Traits&gt;&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:121: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::basic_ios&lt;_CharT, _Traits&gt;&amp; (</em>)(std::basic_ios&lt;_CharT, _Traits&gt;&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:131: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::ios_base&amp; (<em>)(std::ios_base&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:169: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:177: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:185: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(bool) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/bits/ostream.tcc:92: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(short int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:196: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(short unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/bits/ostream.tcc:106: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:207: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:220: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long long int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:228: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long long unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:237: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(double) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:245: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(float) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:253: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long double) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:261: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(const void</em>) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/bits/ostream.tcc:120: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::basic_streambuf&lt;_CharT, _Traits&gt;*) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]</p>
<p>Habt ihr vielleicht eine Idee woran das liegen könnte?</p>
<p>Vielen Dank!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/313004/c-klassen</link><generator>RSS for Node</generator><lastBuildDate>Sun, 02 Aug 2026 08:41:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/313004.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 19 Jan 2013 13:02:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [C++] Klassen on Sat, 19 Jan 2013 13:19:24 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Edit: Ich entschuldige mich dafür, dass mein Code so lange ist. Ich habe jetzt vesucht ihn so viel wie möglich zu kürzen.</p>
<p>Im folgenden Code versuche ich drei Klassen zu Erstellen &quot;atom&quot; &quot;molecule&quot; und &quot;material&quot;.</p>
<p>molecule soll friend von atom sein, und material abgeleitet von molecule.</p>
<p>Die ersten beiden Klassen habe ich erstellt, bei &quot;material&quot; bekomme ich aber kryptische Error Meldungen.</p>
<p>Ich würde mich über jede Hilfe freuen!</p>
<pre><code>#include&lt;iostream&gt;
#include&lt;string&gt;
#include&lt;fstream&gt;
#include&lt;cstdio&gt;
#include&lt;cmath&gt;
#include&lt;locale&gt;
#include&lt;iomanip&gt;

using namespace std;

class atom
{
	friend class molecule;

	private:
		string Element;
		int Ordnungszahl;
		double Atommasse;

	public:	

		atom(string Name, int Z, double m):Element(Name),Ordnungszahl(Z),Atommasse(m){}

		~atom(){};
};

class molecule
{
	private:
		atom Atomart_1;
		atom Atomart_2;
		string Summenformel;
		int Anzahl_1, Anzahl_2;
		char a,b;
		double M;

	public:
		molecule(atom E_1, atom E_2, int A_1, int A_2):
					Atomart_1(E_1), Atomart_2(E_2), Anzahl_1(A_1), Anzahl_2(A_2)
		{
			M=Anzahl_1*Atomart_1.Atommasse+Anzahl_2*Atomart_2.Atommasse;
			char g=Anzahl_1+48;
			char h=Anzahl_2+48;
			Summenformel=Atomart_1.Element+g +Atomart_2.Element+ h;
		};

		~molecule(){};
};

class material:public molecule
{
	private:
		double Schmelzpunkt, Siedepunkt, Temperatur;
		string Aggregatzustand;
		molecule Molecule;

	public:
		material(molecule Mo, double Smp, double Sdp):
					Molecule(Mo), Schmelzpunkt(Smp), Siedepunkt(Sdp){}

		void show2()
		{		
			cout&lt;&lt;&quot;Der Schmelzpunkt von &quot;&lt;&lt;Molecule&lt;&lt;&quot; liegt bei &quot;&lt;&lt;Schmelzpunkt
				 &lt;&lt;&quot; K, und der Siedepunkt bei &quot;&lt;&lt;Siedepunkt&lt;&lt;&quot; K.&quot; &lt;&lt;endl;
		};

	~material(){}
};

int main()
{
	atom Wasserstoff(&quot;H&quot;, 1, 1.00794);

	atom Sauerstoff(&quot;O&quot;, 8, 15.9994);

	molecule H2O(Wasserstoff, Sauerstoff, 2, 1);

	material Wasser(H2O, 273.15, 373.15);
	Wasser.show2(); 

	return 0;
}
</code></pre>
<p>Der Kompiler spuckt folgende Error Meldungen aus</p>
<p>Test.cpp: In constructor ‘material::material(molecule, double, double)’:<br />
Test.cpp:55: warning: ‘material::Molecule’ will be initialized after<br />
Test.cpp:53: warning: ‘double material::Schmelzpunkt’<br />
Test.cpp:58: warning: when initialized here<br />
Test.cpp:59: error: no matching function for call to ‘molecule::molecule()’<br />
Test.cpp:38: note: candidates are: molecule::molecule(atom, atom, int, int)<br />
Test.cpp:28: note: molecule::molecule(const molecule&amp;)<br />
Test.cpp: In member function ‘void material::show2()’:<br />
Test.cpp:63: error: no match for ‘operator&lt;&lt;’ in ‘std::operator&lt;&lt; [with _Traits = std::char_traits&lt;char&gt;](((std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;)(&amp; std::cout)), ((const char*)&quot;Der Schmelzpunkt von &quot;)) &lt;&lt; ((material*)this)-&gt;material::Molecule’<br />
/usr/include/c++/4.2.1/ostream:112: note: candidates are: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp; (<em>)(std::basic_ostream&lt;_CharT, _Traits&gt;&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:121: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::basic_ios&lt;_CharT, _Traits&gt;&amp; (</em>)(std::basic_ios&lt;_CharT, _Traits&gt;&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:131: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::ios_base&amp; (<em>)(std::ios_base&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:169: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:177: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:185: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(bool) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/bits/ostream.tcc:92: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(short int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:196: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(short unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/bits/ostream.tcc:106: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:207: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:220: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long long int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:228: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long long unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:237: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(double) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:245: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(float) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:253: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long double) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/ostream:261: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(const void</em>) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]<br />
/usr/include/c++/4.2.1/bits/ostream.tcc:120: note: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::basic_streambuf&lt;_CharT, _Traits&gt;*) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]</p>
<p>Habt ihr vielleicht eine Idee woran das liegen könnte?</p>
<p>Vielen Dank!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2291283</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291283</guid><dc:creator><![CDATA[natty_dread]]></dc:creator><pubDate>Sat, 19 Jan 2013 13:19:24 GMT</pubDate></item><item><title><![CDATA[Reply to [C++] Klassen on Sat, 19 Jan 2013 13:16:56 GMT]]></title><description><![CDATA[<p>Warum wird material von molecule abgeleitet, hat aber auch ein molecule Member? Die molecule Basis wird nur per Defaultkonstruktor initialisiert, den du aber nicht hast.</p>
<p>In deinem Code ist kein Outputoperator für molecule definiert, Molecule kann in show2 also nicht ausgegeben werden.</p>
<p>Du willst wohl Wasser.show2 und nicht H2O.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2291292</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291292</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sat, 19 Jan 2013 13:16:56 GMT</pubDate></item><item><title><![CDATA[Reply to [C++] Klassen on Sat, 19 Jan 2013 13:20:58 GMT]]></title><description><![CDATA[<p>Richtig, das habe ich nicht bemerkt.</p>
<p>Es sollte tatsächlich Wasser.show2() sein!</p>
<p>Den ersten Teil deines Beitrags verstehe ich leider nicht (ich bin ein Neuling was Programmieren angeht)...</p>
<p>Könntest du das etwas genauer erklären?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2291295</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291295</guid><dc:creator><![CDATA[natty_dread]]></dc:creator><pubDate>Sat, 19 Jan 2013 13:20:58 GMT</pubDate></item><item><title><![CDATA[Reply to [C++] Klassen on Sat, 19 Jan 2013 13:29:31 GMT]]></title><description><![CDATA[<p>Vielleicht solltest du als erstes über die Frage nachdenken und sie beantworten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2291304</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291304</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sat, 19 Jan 2013 13:29:31 GMT</pubDate></item><item><title><![CDATA[Reply to [C++] Klassen on Sat, 19 Jan 2013 14:10:39 GMT]]></title><description><![CDATA[<p><strong>Ist</strong> ein Material ein Molekül oder <strong>hat</strong> ein Material ein Molekül?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2291309</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291309</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 19 Jan 2013 14:10:39 GMT</pubDate></item><item><title><![CDATA[Reply to [C++] Klassen on Sat, 19 Jan 2013 16:13:03 GMT]]></title><description><![CDATA[<p>Ein Material hat ein Molekül.</p>
<p>Ich glaube ich habe meinen Fehler verstanden. Danke für eure Hilfe!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2291356</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291356</guid><dc:creator><![CDATA[natty_dread]]></dc:creator><pubDate>Sat, 19 Jan 2013 16:13:03 GMT</pubDate></item></channel></rss>