<?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[<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

class test
{

};

ostream&amp; operator&lt;&lt;(ostream&amp; os, const test&amp; d)
{
    return os &lt;&lt; &quot;hallo&quot;;   // Wieso eine Referenz zurückgeben?
}

int main()
{

test t;
cout&lt;&lt;t;

return 0;
}
</code></pre>
<p>Warum muss man hier eine Referenz zurück geben?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/313720/operatorüberladung</link><generator>RSS for Node</generator><lastBuildDate>Sat, 01 Aug 2026 22:36:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/313720.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 08 Feb 2013 12:43:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Operatorüberladung on Fri, 08 Feb 2013 12:43:48 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

class test
{

};

ostream&amp; operator&lt;&lt;(ostream&amp; os, const test&amp; d)
{
    return os &lt;&lt; &quot;hallo&quot;;   // Wieso eine Referenz zurückgeben?
}

int main()
{

test t;
cout&lt;&lt;t;

return 0;
}
</code></pre>
<p>Warum muss man hier eine Referenz zurück geben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2297091</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2297091</guid><dc:creator><![CDATA[overL]]></dc:creator><pubDate>Fri, 08 Feb 2013 12:43:48 GMT</pubDate></item><item><title><![CDATA[Reply to Operatorüberladung on Fri, 08 Feb 2013 12:45:16 GMT]]></title><description><![CDATA[<p>Kennst du diese Schreibweise?</p>
<pre><code>std::cout &lt;&lt; 1+1 &lt;&lt; &quot; = &quot; &lt;&lt; x &lt;&lt; &quot;\n&quot; &lt;&lt;std::endl;
std::cin &gt;&gt; a &gt;&gt; b &gt;&gt; c;
</code></pre>
<p>Und genau dafür sit die Rückgabe da, eine Referenz ist es deswegen, weil man einen Stream nicht kopieren kann (ist verboten).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2297092</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2297092</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Fri, 08 Feb 2013 12:45:16 GMT</pubDate></item><item><title><![CDATA[Reply to Operatorüberladung on Fri, 08 Feb 2013 12:55:14 GMT]]></title><description><![CDATA[<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>eine Referenz ist es deswegen, weil man einen Stream nicht kopieren kann (ist verboten).</p>
</blockquote>
<p>Das ist nicht der Grund. Man würde auch eine Referenz nehmen, wenn Streams kopierbar wären.</p>
<p>Man <strong>will</strong> hier keine Kopie, sondern das originale Objekt. Erst durch die Referenz wird die Verkettung mehrerer Operationen auf einem Objekt möglich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2297105</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2297105</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Fri, 08 Feb 2013 12:55:14 GMT</pubDate></item><item><title><![CDATA[Reply to Operatorüberladung on Fri, 08 Feb 2013 13:47:18 GMT]]></title><description><![CDATA[<p>Warum muss überhaupt ein Wert zurück geben werden? Es wird da doch nur das Objekt verändert.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

void foo_1 ( int &amp;v  )
{
   v = 8;
}

int foo_2 ( int &amp;v  )
{
   v = 8;
   return v;
}

int main()
{
int a = 20;

foo_1 ( a );
cout&lt;&lt; a &lt;&lt; &quot;\n&quot;;

cout &lt;&lt; foo_2 ( a ) &lt;&lt; &quot;\n&quot;;

return 0;
}
</code></pre>
<p>Wenn ich doch hier z.b. nur die Variable a verändern will dann brauch ich da ja kein return in den foo Funktionen.</p>
<p>Auch bei der Operatorüberladung sehe ich nicht den Sinn des Rückgabewertes.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2297134</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2297134</guid><dc:creator><![CDATA[overL]]></dc:creator><pubDate>Fri, 08 Feb 2013 13:47:18 GMT</pubDate></item><item><title><![CDATA[Reply to Operatorüberladung on Fri, 08 Feb 2013 13:55:06 GMT]]></title><description><![CDATA[<p>overL schrieb:</p>
<blockquote>
<p>Auch bei der Operatorüberladung sehe ich nicht den Sinn des Rückgabewertes.</p>
</blockquote>
<p>--&gt;</p>
<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>Kennst du diese Schreibweise?</p>
<pre><code>std::cout &lt;&lt; 1+1 &lt;&lt; &quot; = &quot; &lt;&lt; x &lt;&lt; &quot;\n&quot; &lt;&lt;std::endl;
std::cin &gt;&gt; a &gt;&gt; b &gt;&gt; c;
</code></pre>
</blockquote>
<p>anders geschrieben ist das</p>
<pre><code class="language-cpp">operator&lt;&lt;(operator&lt;&lt;(operator&lt;&lt;(operator&lt;&lt;(std::cout, &quot;\n&quot;), x), &quot; = &quot;), 1+1);
</code></pre>
<p>kann sein, dass ich mich da jetzt bei der Auswertungsreihenfolge vertan habe. Aber zur Demonstration des Prinzips sollte es reichen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2297139</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2297139</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Fri, 08 Feb 2013 13:55:06 GMT</pubDate></item><item><title><![CDATA[Reply to Operatorüberladung on Fri, 08 Feb 2013 14:02:36 GMT]]></title><description><![CDATA[<p>@overL:</p>
<p>Was wird denn in deinem Beispiel ausgegeben?<br />
Oder lässt es sich überhaupt kompilieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2297142</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2297142</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Fri, 08 Feb 2013 14:02:36 GMT</pubDate></item><item><title><![CDATA[Reply to Operatorüberladung on Fri, 08 Feb 2013 14:10:19 GMT]]></title><description><![CDATA[<p>In welchem meiner Beispiele?<br />
Beide Beispiele lassen sich compilieren, beim ersten wird der String hallo ausgeben und beim anderen zweimal die 8.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2297146</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2297146</guid><dc:creator><![CDATA[overL]]></dc:creator><pubDate>Fri, 08 Feb 2013 14:10:19 GMT</pubDate></item><item><title><![CDATA[Reply to Operatorüberladung on Fri, 08 Feb 2013 14:40:27 GMT]]></title><description><![CDATA[<p>overL schrieb:</p>
<blockquote>
<p>Beide Beispiele lassen sich compilieren...</p>
</blockquote>
<p>...und haben nichts miteinander zu tun, da du in deinen Beispielen keine Funktionsverkettung machst.</p>
<p>Würdest du void zurückliefern, könntest du keine Verkettung durchführen. Die Verkettung von &quot;&lt;&lt;&quot; ist nur möglich, da jeweils wieder die ostream-Referenz zurückgegeben wurde (Diese Rückgabe wird als erstes Argument des nächsten Funktionsaufrufes von operator&lt;&lt; als linkes Argument verwendet). daddy_felix hat geschrieben wie in etwa operator&lt;&lt; miteinander verkettet wird (Es ist einfach eine Funktionsverschachtelung, bei dem das erste Argument aus dem vorherigen Aufruf übernommen wird).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2297160</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2297160</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Fri, 08 Feb 2013 14:40:27 GMT</pubDate></item><item><title><![CDATA[Reply to Operatorüberladung on Fri, 08 Feb 2013 14:48:06 GMT]]></title><description><![CDATA[<p>Habs verstanden:</p>
<pre><code class="language-cpp">cout &lt;&lt; hex &lt;&lt; &quot;cout addr1: &quot; &lt;&lt; cout &lt;&lt; &quot;\n&quot;;
cout &lt;&lt; &quot;cout addr2: &quot; &lt;&lt; operator&lt;&lt;(cout,&quot;ok&quot;);
</code></pre>
<p>Jetzt leuchtet mir das auch ein.^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2297166</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2297166</guid><dc:creator><![CDATA[overL]]></dc:creator><pubDate>Fri, 08 Feb 2013 14:48:06 GMT</pubDate></item><item><title><![CDATA[Reply to Operatorüberladung on Fri, 08 Feb 2013 18:05:40 GMT]]></title><description><![CDATA[<p>daddy_felix schrieb:</p>
<blockquote>
<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>Kennst du diese Schreibweise?</p>
<pre><code>std::cout &lt;&lt; 1+1 &lt;&lt; &quot; = &quot; &lt;&lt; x &lt;&lt; &quot;\n&quot; &lt;&lt;std::endl;
std::cin &gt;&gt; a &gt;&gt; b &gt;&gt; c;
</code></pre>
</blockquote>
<p>anders geschrieben ist das</p>
<pre><code class="language-cpp">operator&lt;&lt;(operator&lt;&lt;(operator&lt;&lt;(operator&lt;&lt;(std::cout, &quot;\n&quot;), x), &quot; = &quot;), 1+1);
</code></pre>
<p>kann sein, dass ich mich da jetzt bei der Auswertungsreihenfolge vertan habe. Aber zur Demonstration des Prinzips sollte es reichen.</p>
</blockquote>
<p>Das reicht mit Sicherheit. Trotzdem...</p>
<p>&lt;klugscheiss&gt;<br />
...es sind auch Überladungen des member <code>operator&lt;&lt;()</code> dabei (für den <code>int</code> und den <code>endl</code> -Manipulator - und vielleicht auch für x). Also</p>
<pre><code class="language-cpp">std::string x = &quot;Furble Wurble war hier&quot;;  // beispielhaft...
operator&lt;&lt;(operator&lt;&lt;(operator&lt;&lt;(std::cout.operator&lt;&lt;(1+1), &quot; = &quot;), x), &quot;\n&quot;).operator&lt;&lt;(std::endl);
</code></pre>
<p>&lt;/klugscheiss&gt;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2297231</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2297231</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Fri, 08 Feb 2013 18:05:40 GMT</pubDate></item></channel></rss>