<?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[Operatorüberladung]]></title><description><![CDATA[<p>Hallo,<br />
in meinem Buch steht ein Beispiel, wie man einen Vektor (als Klasse) mit einem anderen addieren kann. Dabei wurde folgender Code vorgestellt (man beachte, dass die Variablen <em>x, y, z public</em> sind!:</p>
<pre><code class="language-cpp">inline tbVector3 operator + (const tbVector3 &amp;a, const tbVector3 &amp;b)
{
    return a.x + b.x, a.y + b.y, a.z + b.z;
}
</code></pre>
<p>So wenn ich ihn nun übernehmen wollte, dass sagt mir die IDE, dass zu viele Parameter für die Operator-Funktion vorhanden sind. Er fordert also exakt einen Parameter. Ich verstehe nicht wieso, denn wenn ich das Beispiel (cpp-Datei) von der Buch-CD in meinen Compiler kopiere, dann übernimmt er das einfach. Meine Lösung war jetzt etwas abgeändert:</p>
<pre><code class="language-cpp">inline tbVector3 operator + (const tbVector3 &amp;b)
{
    tbVector3 a(this-&gt;x, this-&gt;y, this-&gt;z); // Übergebe die Daten der aktuellen Instanz
    return a.x + b.x, a.y + b.y, a.z + b.z;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/298054/operatorüberladung</link><generator>RSS for Node</generator><lastBuildDate>Fri, 14 Aug 2026 03:14:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/298054.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 12 Jan 2012 15:39:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Operatorüberladung on Thu, 12 Jan 2012 15:39:05 GMT]]></title><description><![CDATA[<p>Hallo,<br />
in meinem Buch steht ein Beispiel, wie man einen Vektor (als Klasse) mit einem anderen addieren kann. Dabei wurde folgender Code vorgestellt (man beachte, dass die Variablen <em>x, y, z public</em> sind!:</p>
<pre><code class="language-cpp">inline tbVector3 operator + (const tbVector3 &amp;a, const tbVector3 &amp;b)
{
    return a.x + b.x, a.y + b.y, a.z + b.z;
}
</code></pre>
<p>So wenn ich ihn nun übernehmen wollte, dass sagt mir die IDE, dass zu viele Parameter für die Operator-Funktion vorhanden sind. Er fordert also exakt einen Parameter. Ich verstehe nicht wieso, denn wenn ich das Beispiel (cpp-Datei) von der Buch-CD in meinen Compiler kopiere, dann übernimmt er das einfach. Meine Lösung war jetzt etwas abgeändert:</p>
<pre><code class="language-cpp">inline tbVector3 operator + (const tbVector3 &amp;b)
{
    tbVector3 a(this-&gt;x, this-&gt;y, this-&gt;z); // Übergebe die Daten der aktuellen Instanz
    return a.x + b.x, a.y + b.y, a.z + b.z;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2167208</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167208</guid><dc:creator><![CDATA[klucki9]]></dc:creator><pubDate>Thu, 12 Jan 2012 15:39:05 GMT</pubDate></item><item><title><![CDATA[Reply to Operatorüberladung on Thu, 12 Jan 2012 16:03:35 GMT]]></title><description><![CDATA[<p>Schau nochmal genau: Die erste Variante ist eine globale Funktion, die zweite eine Memberfunktion <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>Btw: Das return Statement ist wohl in beiden Fällen nicht was du willst. Du willst wohl eher return tbVector3(x, y, z);</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2167219</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167219</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Thu, 12 Jan 2012 16:03:35 GMT</pubDate></item><item><title><![CDATA[Reply to Operatorüberladung on Thu, 12 Jan 2012 16:06:36 GMT]]></title><description><![CDATA[<p>dot schrieb:</p>
<blockquote>
<p>Schau nochmal genau: Die erste Variante ist eine globale Funktion, die zweite eine Memberfunktion <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>
</blockquote>
<p>Ah, okay, ich werds nochmal nachlesen <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>
<blockquote>
<p>Btw: Das return Statement ist wohl in beiden Fällen nicht was du willst. Du willst wohl eher return tbVector3(x, y, z);</p>
</blockquote>
<p>Stimmt, tut mir Leid da ist was weggelaufen <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="😉"
    /> Richtig wäre natürlich:</p>
<pre><code class="language-cpp">inline tbVector3 operator + (const tbVector3 &amp;a, const tbVector3 &amp;b)
{
    return tbVector3(a.x + b.x, a.y + b.y, a.z + b.z);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2167223</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167223</guid><dc:creator><![CDATA[klucki9]]></dc:creator><pubDate>Thu, 12 Jan 2012 16:06:36 GMT</pubDate></item><item><title><![CDATA[Reply to Operatorüberladung on Thu, 12 Jan 2012 18:12:44 GMT]]></title><description><![CDATA[<p>Warum lässt sich der Vector überhaupt über einen einzelnen Wert konstruieren? Der Konstruktor sollte auf jeden Fall als explicit markiert sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2167313</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167313</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Thu, 12 Jan 2012 18:12:44 GMT</pubDate></item><item><title><![CDATA[Reply to Operatorüberladung on Thu, 12 Jan 2012 18:33:17 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<p>Warum lässt sich der Vector überhaupt über einen einzelnen Wert konstruieren? Der Konstruktor sollte auf jeden Fall als explicit markiert sein.</p>
</blockquote>
<p>Ich bezweifle dass sich der Code von oben so compilieren ließ, wenn er ihn aus dem Buch übernommen hat. Eben weil ein Konstrutktor, der nur ein Argument annimmt sinnfrei wäre, egal ob explicit oder nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2167327</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2167327</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 12 Jan 2012 18:33:17 GMT</pubDate></item></channel></rss>