<?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[initialiser list]]></title><description><![CDATA[<p>hi</p>
<p>auszug aus meinem code:</p>
<pre><code>class Node
	{
		// ...
		NodeType _nt;
		union
		{
			struct
			{
				Node *_lhs, *_rhs;
			} _ptrpair;
			ValueType _val;
		} _d;
		// ...
	}
</code></pre>
<p>nun biete ich mehrere konstruktoren an, mit denen jeweils der eine oder der andere teil der union genutzt werden. ich hab versucht einen der konstruktoren zu schreiben, der dann etwa so aussah:</p>
<pre><code>InterpretedMath::Node::Node()
: _nt(ntValue), _d._val(0)
{
}
</code></pre>
<p>mit diesem _d._val war der compiler aber gar nicht einverstanden. auszug aus der ideone.com-meldung:</p>
<blockquote>
<p>prog.cpp: In constructor ‘InterpretedMath::Node::Node()’:<br />
prog.cpp:57:19: error: expected ‘(’ before ‘.’ token<br />
: _nt(ntValue), _d._val(0)<br />
^</p>
</blockquote>
<p>wie sonst soll das gehen? darf ich also die initialiser list nicht nutzen?<br />
gruss</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/319618/initialiser-list</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Jul 2026 04:10:28 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/319618.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 26 Aug 2013 09:00:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to initialiser list on Mon, 26 Aug 2013 09:00:39 GMT]]></title><description><![CDATA[<p>hi</p>
<p>auszug aus meinem code:</p>
<pre><code>class Node
	{
		// ...
		NodeType _nt;
		union
		{
			struct
			{
				Node *_lhs, *_rhs;
			} _ptrpair;
			ValueType _val;
		} _d;
		// ...
	}
</code></pre>
<p>nun biete ich mehrere konstruktoren an, mit denen jeweils der eine oder der andere teil der union genutzt werden. ich hab versucht einen der konstruktoren zu schreiben, der dann etwa so aussah:</p>
<pre><code>InterpretedMath::Node::Node()
: _nt(ntValue), _d._val(0)
{
}
</code></pre>
<p>mit diesem _d._val war der compiler aber gar nicht einverstanden. auszug aus der ideone.com-meldung:</p>
<blockquote>
<p>prog.cpp: In constructor ‘InterpretedMath::Node::Node()’:<br />
prog.cpp:57:19: error: expected ‘(’ before ‘.’ token<br />
: _nt(ntValue), _d._val(0)<br />
^</p>
</blockquote>
<p>wie sonst soll das gehen? darf ich also die initialiser list nicht nutzen?<br />
gruss</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348541</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348541</guid><dc:creator><![CDATA[doktor banane]]></dc:creator><pubDate>Mon, 26 Aug 2013 09:00:39 GMT</pubDate></item><item><title><![CDATA[Reply to initialiser list on Mon, 26 Aug 2013 09:13:49 GMT]]></title><description><![CDATA[<p>Die Snytax ist an sich richtig. Aber wo ist die Variable ntValue deklariert? Es ist ja kein Parameter des Konstruktors...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348545</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348545</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Mon, 26 Aug 2013 09:13:49 GMT</pubDate></item><item><title><![CDATA[Reply to initialiser list on Mon, 26 Aug 2013 09:17:22 GMT]]></title><description><![CDATA[<p>Du kannst nur Member der aktuellen Klasse initialiseren. Du müsstest also wenn schon _d initialisieren. Ich hab keine Ahnung, ob das geht, aber da unions sowieso nur POD enthalten dürfen (wie auch bei dir), vergibst du nichts, wenn du erst im Konstruktor-Body eine Zuweisung machst.</p>
<pre><code class="language-cpp">InterpretedMath::Node::Node()
: _nt(ntValue)
{
    _d._val = 0;
}
</code></pre>
<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>Die Snytax ist an sich richtig.</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /> In welcher Sprache?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348548</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348548</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Mon, 26 Aug 2013 09:17:22 GMT</pubDate></item><item><title><![CDATA[Reply to initialiser list on Mon, 26 Aug 2013 09:17:54 GMT]]></title><description><![CDATA[<p>Jetzt bin ich stark verwirrt. Mir sieht die Syntax völlig falsch aus, wieso, Skym0sh0, sagst du dass sie richtig ist?<br />
Edit: Thx, Bashar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348550</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348550</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Mon, 26 Aug 2013 09:17:54 GMT</pubDate></item><item><title><![CDATA[Reply to initialiser list on Mon, 26 Aug 2013 09:18:27 GMT]]></title><description><![CDATA[<p>ntValue ist ein status des enums NodeType, hab ich vergessen zu erwähnen, sry</p>
<p>der fehler tritt aber weiter hinten in der inizialisierungsliste auf, da steht ja so ein ^ mit welchem der ort markiert ist. (ups, sehe grad, dass das forum die whitespaces weggemacht hat <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f611.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--expressionless_face"
      title="-_-"
      alt="😑"
    /> es war ursprünglich direkt unter dem punkt nach _d)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348551</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348551</guid><dc:creator><![CDATA[doktor banane]]></dc:creator><pubDate>Mon, 26 Aug 2013 09:18:27 GMT</pubDate></item><item><title><![CDATA[Reply to initialiser list on Mon, 26 Aug 2013 09:19:31 GMT]]></title><description><![CDATA[<p>okay, zwei neue posts während ich meinen letzten geschrieben habe. alles klar nun, danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348554</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348554</guid><dc:creator><![CDATA[doktor banane]]></dc:creator><pubDate>Mon, 26 Aug 2013 09:19:31 GMT</pubDate></item><item><title><![CDATA[Reply to initialiser list on Mon, 26 Aug 2013 09:50:32 GMT]]></title><description><![CDATA[<p>Echt jetzt?</p>
<p>Ich dachte, das geht so ohne Probleme. Mit Unions hab ich keine Erfahrung, sosnt wärs mir aufgefallen.</p>
<p>Naja ok, danke Leute. (Ich sollte echt mehr denken und genauer lesen bevor ich schreibe)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348562</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348562</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Mon, 26 Aug 2013 09:50:32 GMT</pubDate></item><item><title><![CDATA[Reply to initialiser list on Mon, 26 Aug 2013 10:50:41 GMT]]></title><description><![CDATA[<p>An dieser Stelle wäre es schön, wie in C die zu initialisierenden Member direkt in der Aggregat-Initialisierungsliste angeben zu können.<br />
In C++11 können wir uns auch anders behelfen (<a href="http://ideone.com/exotTh" rel="nofollow">ideone</a>):</p>
<pre><code class="language-cpp">struct Node;
using ValueType = int;

union d_type
{
    struct
    {
        Node *_lhs, *_rhs;
    } _ptrpair;
    ValueType _val;

    d_type() noexcept = default;
    d_type(const d_type&amp;) noexcept = default;
    d_type(d_type&amp;&amp;) noexcept = default;
    d_type&amp; operator=(const d_type&amp;) noexcept = default;
    d_type&amp; operator=(d_type&amp;&amp;) noexcept = default;
    ~d_type() noexcept = default;

    d_type(const ValueType&amp; v) noexcept
    {
        _val = v;
    }
    d_type(Node* lhs, Node* rhs) noexcept
    {
        _ptrpair = { lhs, rhs };
    }
};

d_type a{ nullptr, nullptr };
d_type b{ 0 };
int main(){}
</code></pre>
<p>Das ist damit kein Aggregat mehr, ist aber weiterhin trivial und hat Standardlayout, lowlevel-Schweinereien funktionieren also i.d.R. weiterhin.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348568</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348568</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 26 Aug 2013 10:50:41 GMT</pubDate></item></channel></rss>