<?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[&amp;quot;Exotischer&amp;quot; Konstruktor]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe kürzlich und eine neue &quot;Art&quot; Konstruktor entdeckt und wollte mal fragen, ob es zwischen den beiden Typen einen Unterschied gibt.</p>
<p>Konstruktor Typ A:</p>
<pre><code>class VehikelA{

private:
int Leistung;

public:
// Typ A (normal)
	VehikelA(int iLeistung){
	Leistung = iLeistung;
	}

};
</code></pre>
<p>Konstruktor Typ B:</p>
<pre><code>class VehikelB{

private:
int Leistung;

public:
// Typ B (exotisch)
	VehikelB(int iLeistung):Leistung(iLeistung){}

};
</code></pre>
<p>Kann mir bitte jemand den Konstruktor Typ B erklären. Und gibt es einen Unterschied zwischend den beiden Varianten?</p>
<p>Vielen Dank schon jetzt für alle Antworten<br />
Valjean</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/312491/quot-exotischer-quot-konstruktor</link><generator>RSS for Node</generator><lastBuildDate>Sun, 02 Aug 2026 18:46:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/312491.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 06 Jan 2013 14:41:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to &amp;quot;Exotischer&amp;quot; Konstruktor on Sun, 06 Jan 2013 14:41:48 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe kürzlich und eine neue &quot;Art&quot; Konstruktor entdeckt und wollte mal fragen, ob es zwischen den beiden Typen einen Unterschied gibt.</p>
<p>Konstruktor Typ A:</p>
<pre><code>class VehikelA{

private:
int Leistung;

public:
// Typ A (normal)
	VehikelA(int iLeistung){
	Leistung = iLeistung;
	}

};
</code></pre>
<p>Konstruktor Typ B:</p>
<pre><code>class VehikelB{

private:
int Leistung;

public:
// Typ B (exotisch)
	VehikelB(int iLeistung):Leistung(iLeistung){}

};
</code></pre>
<p>Kann mir bitte jemand den Konstruktor Typ B erklären. Und gibt es einen Unterschied zwischend den beiden Varianten?</p>
<p>Vielen Dank schon jetzt für alle Antworten<br />
Valjean</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2286779</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2286779</guid><dc:creator><![CDATA[Valjean]]></dc:creator><pubDate>Sun, 06 Jan 2013 14:41:48 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Exotischer&amp;quot; Konstruktor on Sun, 06 Jan 2013 14:42:40 GMT]]></title><description><![CDATA[<p>Stichwort: Initialisierungsliste</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2286780</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2286780</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Sun, 06 Jan 2013 14:42:40 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Exotischer&amp;quot; Konstruktor on Sun, 06 Jan 2013 15:05:29 GMT]]></title><description><![CDATA[<p>Du hast da was vertauscht</p>
<pre><code class="language-cpp">// Typ A (exotisch)
    VehikelA(int Leistung){
    this-&gt;Leistung = Leistung;
    }
</code></pre>
<pre><code class="language-cpp">// Typ B (normal)
    VehikelB(int Leistung):Leistung(Leistung){}
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2286793</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2286793</guid><dc:creator><![CDATA[normalo]]></dc:creator><pubDate>Sun, 06 Jan 2013 15:05:29 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Exotischer&amp;quot; Konstruktor on Sun, 06 Jan 2013 15:37:05 GMT]]></title><description><![CDATA[<p>In der Tat hast du das verwechselt. Erstere Version ist die exotischere!</p>
<p>in der normalen Version</p>
<pre><code>VehikelA(int iLeistung) : Leistung(iLeistung) {}
</code></pre>
<p>wird <code>Leistung</code> mit <code>iLeistung</code> initialisiert.</p>
<p>in der zweiten Version</p>
<pre><code>VehikelA(int iLeistung) 
{
  Leistung = iLeistung;
}
</code></pre>
<p>wird Leistung default-initialisiert und dann wird <code>iLeistung</code> nach <code>Leistung</code> kopiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2286807</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2286807</guid><dc:creator><![CDATA[ScottZhang]]></dc:creator><pubDate>Sun, 06 Jan 2013 15:37:05 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Exotischer&amp;quot; Konstruktor on Sun, 06 Jan 2013 17:29:06 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>vielen Dank für die schnellen Antworten. Ich sah bisher eben immer nur Variante A - gut ich bin auch ein totaler Anfäger.</p>
<p>@Scott<br />
<em>in der zweiten Version wird Leistung default-initialisiert und dann wird iLeistung nach Leistung kopiert.</em></p>
<p>Kannst du mir noch etwas genauer erklären, oder einen Tipp geben, was damit gemeint ist?<br />
Ich dachte der default-Konstruktor wird nur dann aufgerufen, wenn dem Objekt keine Parameter übergeben werden, was hier ja nicht der Fall ist.</p>
<p>Vielen Dank für alle Tipps <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="😃"
    /><br />
Valjean</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2286890</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2286890</guid><dc:creator><![CDATA[Valjean]]></dc:creator><pubDate>Sun, 06 Jan 2013 17:29:06 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Exotischer&amp;quot; Konstruktor on Sun, 06 Jan 2013 17:54:36 GMT]]></title><description><![CDATA[<p>Der Ablauf beim Aufruf des Konstruktors A sieht wie folgt aus:<br />
Die (nicht vorhandene) Initialisierungsliste von A wird ausgeführt. Nachdem das erledigt ist, sind die Member initialisiert.<br />
Da nicht näher spezifiziert ist, welcher Konstruktor von Leistung aufgerufen wird, wird der Default-Konstruktor genommen. Der nimmt die vorhanden Bits im Speicher an.<br />
Anschließend wird der Anweisungsteil betreten und der Wert von iLeistung wird nach Leistung kopiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2286892</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2286892</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 06 Jan 2013 17:54:36 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Exotischer&amp;quot; Konstruktor on Sun, 06 Jan 2013 17:51:59 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<p>... Nachdem das erledigt ist, ist die Klasse initialisiert. ...</p>
</blockquote>
<p>Schlechte Formulierung!<br />
Nachdem das erledigt ist, sind die Member initialisiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2286908</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2286908</guid><dc:creator><![CDATA[ScottZhang]]></dc:creator><pubDate>Sun, 06 Jan 2013 17:51:59 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Exotischer&amp;quot; Konstruktor on Sun, 06 Jan 2013 17:51:54 GMT]]></title><description><![CDATA[<p>Ja, ok, meinetwegen... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2286910</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2286910</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 06 Jan 2013 17:51:54 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Exotischer&amp;quot; Konstruktor on Sun, 06 Jan 2013 17:52:51 GMT]]></title><description><![CDATA[<p>Und mit &quot;schlechte Formulierung&quot; meine ich &quot;Falsche&quot; :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2286912</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2286912</guid><dc:creator><![CDATA[ScottZhang]]></dc:creator><pubDate>Sun, 06 Jan 2013 17:52:51 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Exotischer&amp;quot; Konstruktor on Sun, 06 Jan 2013 17:55:29 GMT]]></title><description><![CDATA[<p>Nur mal so nebenbei, wovon redest du eigentlich?<br />
Wann habe ich das geschrieben? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Und wieso wäre die falsch, die Klasse ist doch initalisiert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2286914</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2286914</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 06 Jan 2013 17:55:29 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Exotischer&amp;quot; Konstruktor on Sun, 06 Jan 2013 17:56:35 GMT]]></title><description><![CDATA[<p>a) Klassen werden nicht initialisiert sonder Objekte.</p>
<p>b) Das Objekt ist initilasiert wenn der Konstruktor fertig ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2286918</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2286918</guid><dc:creator><![CDATA[ScottZhang]]></dc:creator><pubDate>Sun, 06 Jan 2013 17:56:35 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Exotischer&amp;quot; Konstruktor on Sun, 06 Jan 2013 18:00:58 GMT]]></title><description><![CDATA[<p>c) Die Member sind zwar default-initialisiert, haben aber nicht immer einen definierten Wert. Ein int-Member könnte jeden beliebigen Wert haben (23512 oder -51215 oder manchmal auch 0). Nur damit wir uns einig sind, was &quot;initialisiert&quot; bedeutet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2286927</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2286927</guid><dc:creator><![CDATA[nachtrag]]></dc:creator><pubDate>Sun, 06 Jan 2013 18:00:58 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Exotischer&amp;quot; Konstruktor on Sun, 06 Jan 2013 18:01:06 GMT]]></title><description><![CDATA[<p>Ja, stimmt eigentlich.<br />
Ist aber schon längst korrigiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2286928</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2286928</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 06 Jan 2013 18:01:06 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Exotischer&amp;quot; Konstruktor on Sun, 06 Jan 2013 18:08:52 GMT]]></title><description><![CDATA[<p>nachtrag schrieb:</p>
<blockquote>
<p>c) Die Member sind zwar default-initialisiert, haben aber nicht immer einen definierten Wert. Ein int-Member könnte jeden beliebigen Wert haben (23512 oder -51215 oder manchmal auch 0). Nur damit wir uns einig sind, was &quot;initialisiert&quot; bedeutet.</p>
</blockquote>
<p>Jopp, weils 'n POD ist kann man nicht default-initialsiert sagen.<br />
POD's bleiben einfach uninitialisiert, wenn sie nicht in der Initialisierungsliste auftauchen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2286933</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2286933</guid><dc:creator><![CDATA[ScottZhang]]></dc:creator><pubDate>Sun, 06 Jan 2013 18:08:52 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Exotischer&amp;quot; Konstruktor on Mon, 07 Jan 2013 06:27:21 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<p>Da nicht näher spezifiziert ist, welcher Konstruktor von Leistung aufgerufen wird, wird der Default-Konstruktor genommen. Der nimmt die vorhanden Bits im Speicher an.</p>
</blockquote>
<p>Hier wird gar kein Konstruktor aufgerufen.<br />
Der Standard spricht in dem Zusammenhang auch nicht von Konstruktoren, sondern davon wie das Member &quot;initialized&quot; wird.<br />
Und in diesem Fall wird halt gar nicht &quot;initialized&quot;.</p>
<p>Es gibt auch keinen &quot;Default-Konstruktor&quot; für Integers. Das was dem &quot;Default-Konstruktor&quot; bei Integers am nähesten kommt ist &quot;zero initialization&quot;, und die übernimmt nicht einfach die Bits an der Stelle im Speicher, sondern initialisiert den Integer mit Null.</p>
<p>Die ganze Initialisierungs-Geschichte ist in C++ halbwegs unübersichtlich und unintuitiv, daher sollte man sich nicht schnell zu Aussagen hinreissen lassen was hier passiert, es sei denn man hat die Sache wirklich genau im Kopf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2287114</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2287114</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 07 Jan 2013 06:27:21 GMT</pubDate></item><item><title><![CDATA[Reply to &amp;quot;Exotischer&amp;quot; Konstruktor on Mon, 07 Jan 2013 06:55:43 GMT]]></title><description><![CDATA[<p>Ja, du hast natürlich recht.<br />
Weil int ein POD ist gilt das natürlich nicht ganz, was ich gesagt habe.<br />
Ich finde allerdings trotzdem, dass man sich dann die Sachen besser vorstellen kann, was da passiert, wenn man es so formuliert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2287120</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2287120</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Mon, 07 Jan 2013 06:55:43 GMT</pubDate></item></channel></rss>