<?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[struct vs. class?]]></title><description><![CDATA[<p>wann sollte man eigentlich struct und wann class nutzen?</p>
<p>ich habe hier eine Klasse, bei der alle Methoden und Membervariablen public sind:</p>
<pre><code class="language-cpp">// Geometry Declarations
class Vector {
public:
    // Vector Public Methods
    Vector() { x = y = z = 0.f; }
    Vector(float xx, float yy, float zz)
        : x(xx), y(yy), z(zz) {
        Assert(!HasNaNs());
    }
    bool HasNaNs() const { return isnan(x) || isnan(y) || isnan(z); }
    explicit Vector(const Point &amp;p);
#ifndef NDEBUG
    // The default versions of these are fine for release builds; for debug
    // we define them so that we can add the Assert checks.
    Vector(const Vector &amp;v) {
        Assert(!v.HasNaNs());
        x = v.x; y = v.y; z = v.z;
    }

    Vector &amp;operator=(const Vector &amp;v) {
        Assert(!v.HasNaNs());
        x = v.x; y = v.y; z = v.z;
        return *this;
    }
#endif // !NDEBUG
    Vector operator+(const Vector &amp;v) const {
        Assert(!v.HasNaNs());
        return Vector(x + v.x, y + v.y, z + v.z);
    }

    Vector&amp; operator+=(const Vector &amp;v) {
        Assert(!v.HasNaNs());
        x += v.x; y += v.y; z += v.z;
        return *this;
    }
...
</code></pre>
<p>macht es Sinn hier struct zu verwenden anstatt class? Sollte man struct nur verwenden wenn man keine Methoden/Konstruktoren hat?</p>
<p>spielt es überhaupt eine Rolle ob man hier struct oder class verwendet? Ist struct nur noch ein Überbleibsel aus C?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/273618/struct-vs-class</link><generator>RSS for Node</generator><lastBuildDate>Fri, 28 Aug 2026 00:26:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/273618.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 09 Sep 2010 21:41:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to struct vs. class? on Thu, 09 Sep 2010 21:41:17 GMT]]></title><description><![CDATA[<p>wann sollte man eigentlich struct und wann class nutzen?</p>
<p>ich habe hier eine Klasse, bei der alle Methoden und Membervariablen public sind:</p>
<pre><code class="language-cpp">// Geometry Declarations
class Vector {
public:
    // Vector Public Methods
    Vector() { x = y = z = 0.f; }
    Vector(float xx, float yy, float zz)
        : x(xx), y(yy), z(zz) {
        Assert(!HasNaNs());
    }
    bool HasNaNs() const { return isnan(x) || isnan(y) || isnan(z); }
    explicit Vector(const Point &amp;p);
#ifndef NDEBUG
    // The default versions of these are fine for release builds; for debug
    // we define them so that we can add the Assert checks.
    Vector(const Vector &amp;v) {
        Assert(!v.HasNaNs());
        x = v.x; y = v.y; z = v.z;
    }

    Vector &amp;operator=(const Vector &amp;v) {
        Assert(!v.HasNaNs());
        x = v.x; y = v.y; z = v.z;
        return *this;
    }
#endif // !NDEBUG
    Vector operator+(const Vector &amp;v) const {
        Assert(!v.HasNaNs());
        return Vector(x + v.x, y + v.y, z + v.z);
    }

    Vector&amp; operator+=(const Vector &amp;v) {
        Assert(!v.HasNaNs());
        x += v.x; y += v.y; z += v.z;
        return *this;
    }
...
</code></pre>
<p>macht es Sinn hier struct zu verwenden anstatt class? Sollte man struct nur verwenden wenn man keine Methoden/Konstruktoren hat?</p>
<p>spielt es überhaupt eine Rolle ob man hier struct oder class verwendet? Ist struct nur noch ein Überbleibsel aus C?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1950551</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1950551</guid><dc:creator><![CDATA[MuhkuhAKAFoobar]]></dc:creator><pubDate>Thu, 09 Sep 2010 21:41:17 GMT</pubDate></item><item><title><![CDATA[Reply to struct vs. class? on Thu, 09 Sep 2010 21:49:06 GMT]]></title><description><![CDATA[<p><code>struct</code> und <code>class</code> als Schlüsselwörter für Klassen sind bis auf die Default-Sichtbarkeit der Member und Basisklassen identisch.</p>
<p>Ich verwende <code>struct</code> eigentlich nur für kleinere Datenbündel (mit öffentlichen Variablen und Konstruktoren), Funktoren und Metafunktionen. Für &quot;richtige&quot; Klassen <code>class</code> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1950556</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1950556</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Thu, 09 Sep 2010 21:49:06 GMT</pubDate></item><item><title><![CDATA[Reply to struct vs. class? on Thu, 09 Sep 2010 22:31:51 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p><code>struct</code> und <code>class</code> als Schlüsselwörter für Klassen sind bis auf die Default-Sichtbarkeit der Member und Basisklassen identisch.</p>
<p>Ich verwende <code>struct</code> eigentlich nur für kleinere Datenbündel (mit öffentlichen Variablen und Konstruktoren), Funktoren und Metafunktionen. Für &quot;richtige&quot; Klassen <code>class</code> .</p>
</blockquote>
<p>Genau, bei struct is per default sprich ohne angaben von einem Zugriffsspezifierer alles public und bei class privat.</p>
<p>Das ist der einzige Unterschied.</p>
<p>Lg freeG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1950569</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1950569</guid><dc:creator><![CDATA[fr33g]]></dc:creator><pubDate>Thu, 09 Sep 2010 22:31:51 GMT</pubDate></item><item><title><![CDATA[Reply to struct vs. class? on Fri, 10 Sep 2010 08:05:19 GMT]]></title><description><![CDATA[<p>Ich denke er kennt den Unterschied wenn ich mir seinen Post so ansehe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /> . Er fragt wie man entscheidet wann welches sinnvoller ist. Wenn die Gegebenheiten wie in deinem Beispiel vorliegen, denke ich das es eine Geschmackssache ist, aber mal warten was die Experten dazu sagen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1950647</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1950647</guid><dc:creator><![CDATA[FruFru]]></dc:creator><pubDate>Fri, 10 Sep 2010 08:05:19 GMT</pubDate></item><item><title><![CDATA[Reply to struct vs. class? on Fri, 10 Sep 2010 08:13:48 GMT]]></title><description><![CDATA[<p>FruFru schrieb:</p>
<blockquote>
<p>Er fragt wie man entscheidet wann welches sinnvoller ist.</p>
</blockquote>
<p>Nexus hat es ja schon schön gesagt. Es bietet sich an, struct im Sinne des ursprünglichen struct aus C für Datensammlungen zu nutzen und class für das volle Programm mit Methoden usw. Finde ich zumindest logisch, letztlich kann es ja jeder machen, wie er will.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1950651</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1950651</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Fri, 10 Sep 2010 08:13:48 GMT</pubDate></item><item><title><![CDATA[Reply to struct vs. class? on Fri, 10 Sep 2010 15:36:36 GMT]]></title><description><![CDATA[<p>Wenn du kompatibel mit C seien möchtest nutz struct andernfalls class.<br />
So seh ich das mal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1950976</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1950976</guid><dc:creator><![CDATA[CCodex]]></dc:creator><pubDate>Fri, 10 Sep 2010 15:36:36 GMT</pubDate></item><item><title><![CDATA[Reply to struct vs. class? on Fri, 10 Sep 2010 15:52:24 GMT]]></title><description><![CDATA[<p>gamebuntu schrieb:</p>
<blockquote>
<p>Wenn du kompatibel mit C seien möchtest nutz struct andernfalls class.<br />
So seh ich das mal.</p>
</blockquote>
<p>Was heißt kompatibel? Entweder macht man C oder nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1950990</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1950990</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 10 Sep 2010 15:52:24 GMT</pubDate></item><item><title><![CDATA[Reply to struct vs. class? on Fri, 10 Sep 2010 17:03:34 GMT]]></title><description><![CDATA[<p>gamebuntu schrieb:</p>
<blockquote>
<p>Wenn du kompatibel mit C seien möchtest nutz struct</p>
</blockquote>
<p>Bringt doch nix, sobald du nen Konstruktor definierst, oder eine Methode.</p>
<p>Außerdem: wieso kompatibel?? Schreibst du deinen C++-Code etwa so, dass ein C-Compiler ihn auch schluckt? Dann schreibst du C-Code. Ist ja, als würdest du sagen, dass man beim Java-Programmieren bloß aufpassen muss, dass er auch &quot;PHP-kompatibel&quot; bleibt. <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="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1951040</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1951040</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Fri, 10 Sep 2010 17:03:34 GMT</pubDate></item></channel></rss>