<?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[Wie optionale Member definieren?]]></title><description><![CDATA[<p>Mahlzeit!</p>
<p>Ich habe eine class Section, die IMMER eine WidthSection sowie eine OPTIONALE InfoSection besitzt. Wie kann ich das am besten ausdrücken?</p>
<p>Idee 1: Per Zeiger (wenn keine InfoSection, ist mInfoSection = NULL)</p>
<pre><code>class Section {
    WidthSection mWidthSection;
    InfoSection* mInfoSection;
};
</code></pre>
<p>Idee 2: Per bool (wenn keine InfoSection, ist mHasInfoSection = false)</p>
<pre><code>class Section {
    WidthSection mWidthSection;

    InfoSection mInfoSection;
    bool mHasInfoSection
};
</code></pre>
<p>Was fändet ihr besser? Oder gibts in C++ einen noch besseren Ansatz?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/328318/wie-optionale-member-definieren</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Jul 2026 03:40:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/328318.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 03 Oct 2014 08:35:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wie optionale Member definieren? on Fri, 03 Oct 2014 08:35:20 GMT]]></title><description><![CDATA[<p>Mahlzeit!</p>
<p>Ich habe eine class Section, die IMMER eine WidthSection sowie eine OPTIONALE InfoSection besitzt. Wie kann ich das am besten ausdrücken?</p>
<p>Idee 1: Per Zeiger (wenn keine InfoSection, ist mInfoSection = NULL)</p>
<pre><code>class Section {
    WidthSection mWidthSection;
    InfoSection* mInfoSection;
};
</code></pre>
<p>Idee 2: Per bool (wenn keine InfoSection, ist mHasInfoSection = false)</p>
<pre><code>class Section {
    WidthSection mWidthSection;

    InfoSection mInfoSection;
    bool mHasInfoSection
};
</code></pre>
<p>Was fändet ihr besser? Oder gibts in C++ einen noch besseren Ansatz?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420545</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420545</guid><dc:creator><![CDATA[optionaler3]]></dc:creator><pubDate>Fri, 03 Oct 2014 08:35:20 GMT</pubDate></item><item><title><![CDATA[Reply to Wie optionale Member definieren? on Fri, 03 Oct 2014 08:36:51 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">boost::optional&lt;InfoSection&gt;
</code></pre>
<p>und in Zukunft</p>
<pre><code class="language-cpp">std::optional&lt;InfoSection&gt;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2420547</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420547</guid><dc:creator><![CDATA[Optionalitätsinterferenz]]></dc:creator><pubDate>Fri, 03 Oct 2014 08:36:51 GMT</pubDate></item><item><title><![CDATA[Reply to Wie optionale Member definieren? on Fri, 03 Oct 2014 08:41:39 GMT]]></title><description><![CDATA[<p>Wieso nicht Vererbung? Section &lt;- InfoSection</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420549</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420549</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Fri, 03 Oct 2014 08:41:39 GMT</pubDate></item><item><title><![CDATA[Reply to Wie optionale Member definieren? on Fri, 03 Oct 2014 09:02:50 GMT]]></title><description><![CDATA[<p>out schrieb:</p>
<blockquote>
<p>Wieso nicht Vererbung? Section &lt;- InfoSection</p>
</blockquote>
<p>Weil es keinen Sinn ergibt. Es ist eine Komposition und keine Vererbung...</p>
<p>@Optionalitätsinterferenz: Danke! Das sieht schon mal sehr gut aus! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420553</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420553</guid><dc:creator><![CDATA[optionaler3]]></dc:creator><pubDate>Fri, 03 Oct 2014 09:02:50 GMT</pubDate></item><item><title><![CDATA[Reply to Wie optionale Member definieren? on Fri, 03 Oct 2014 09:21:07 GMT]]></title><description><![CDATA[<p><code>unique_ptr&lt;InfoSection&gt;</code> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420555</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420555</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Fri, 03 Oct 2014 09:21:07 GMT</pubDate></item><item><title><![CDATA[Reply to Wie optionale Member definieren? on Fri, 03 Oct 2014 09:32:04 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p><code>unique_ptr&lt;InfoSection&gt;</code> .</p>
</blockquote>
<p>Das braucht Heap Memory, optional nicht zwingend.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420558</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420558</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Fri, 03 Oct 2014 09:32:04 GMT</pubDate></item><item><title><![CDATA[Reply to Wie optionale Member definieren? on Fri, 03 Oct 2014 11:34:51 GMT]]></title><description><![CDATA[<p>Schon klar. Ich wollte nur eine zusaetzliche Option vorschlagen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420566</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420566</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Fri, 03 Oct 2014 11:34:51 GMT</pubDate></item></channel></rss>