<?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[Fehler im Stream  [gelöst]]]></title><description><![CDATA[<p>Hallo,<br />
ich habe hier ein Prog mit einem Stream und alles compiliert und läuft. Der Code in der letzten Zeile ist auskommentiert. &quot;myStream() &lt;&lt; my;&quot; Aber genau diesen Code brauche ich. Der gcc ist schwer am motzen, wenn er diesen Code sieht. Unter VC compiliert alles problemlos;</p>
<pre><code>#include &lt;sstream&gt; 
#include &lt;iostream&gt;

using namespace std;

class myStream; 
myStream&amp; my(myStream&amp;);

class myStream
{ 
public: 
	myStream()	{} 	
	~myStream()	{	cout &lt;&lt; &quot;  start &quot; &lt;&lt; o.str() &lt;&lt; &quot; ende  &quot;;	} 

	friend myStream&amp; my(myStream&amp; stream)	{	stream.	o &lt;&lt; &quot;&lt;myStream&gt;&quot;;	return stream;	} 
	myStream&amp; operator&lt;&lt;(const char* m)		{			o &lt;&lt; m;				return *this;	}

private:
	ostringstream o;
}; 

// manipulator function 
inline myStream&amp; operator&lt;&lt;(myStream&amp; stream, myStream&amp; (*function)(myStream&amp;) ) 
{	return (*function)(stream);	} 

int main() 
{
	myStream o;
	o &lt;&lt; my;
	o &lt;&lt; &quot;y&quot;;
	o &lt;&lt; &quot;z&quot; &lt;&lt; my;

	myStream() &lt;&lt; &quot;&quot; &lt;&lt; my &lt;&lt; my &lt;&lt; &quot;&quot; &lt;&lt; my;
//	myStream() &lt;&lt; my;	//  erzeugt untenstehenden error im gcc
}

/*
35: error: no match for 'operator&lt;&lt;' in 'myStream() &lt;&lt; my'
16: note: candidates are: myStream&amp; myStream::operator&lt;&lt;(const char*)
23: note:                 myStream&amp; operator&lt;&lt;(myStream&amp;, myStream&amp; (*)(myStream&amp;))
*/
</code></pre>
<p>Bin für jeden Tip dankbar<br />
tschüß<br />
Troll.Soft</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/267950/fehler-im-stream-gelöst</link><generator>RSS for Node</generator><lastBuildDate>Wed, 02 Sep 2026 05:12:57 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/267950.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 01 Jun 2010 18:19:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fehler im Stream  [gelöst] on Tue, 01 Jun 2010 20:51:39 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe hier ein Prog mit einem Stream und alles compiliert und läuft. Der Code in der letzten Zeile ist auskommentiert. &quot;myStream() &lt;&lt; my;&quot; Aber genau diesen Code brauche ich. Der gcc ist schwer am motzen, wenn er diesen Code sieht. Unter VC compiliert alles problemlos;</p>
<pre><code>#include &lt;sstream&gt; 
#include &lt;iostream&gt;

using namespace std;

class myStream; 
myStream&amp; my(myStream&amp;);

class myStream
{ 
public: 
	myStream()	{} 	
	~myStream()	{	cout &lt;&lt; &quot;  start &quot; &lt;&lt; o.str() &lt;&lt; &quot; ende  &quot;;	} 

	friend myStream&amp; my(myStream&amp; stream)	{	stream.	o &lt;&lt; &quot;&lt;myStream&gt;&quot;;	return stream;	} 
	myStream&amp; operator&lt;&lt;(const char* m)		{			o &lt;&lt; m;				return *this;	}

private:
	ostringstream o;
}; 

// manipulator function 
inline myStream&amp; operator&lt;&lt;(myStream&amp; stream, myStream&amp; (*function)(myStream&amp;) ) 
{	return (*function)(stream);	} 

int main() 
{
	myStream o;
	o &lt;&lt; my;
	o &lt;&lt; &quot;y&quot;;
	o &lt;&lt; &quot;z&quot; &lt;&lt; my;

	myStream() &lt;&lt; &quot;&quot; &lt;&lt; my &lt;&lt; my &lt;&lt; &quot;&quot; &lt;&lt; my;
//	myStream() &lt;&lt; my;	//  erzeugt untenstehenden error im gcc
}

/*
35: error: no match for 'operator&lt;&lt;' in 'myStream() &lt;&lt; my'
16: note: candidates are: myStream&amp; myStream::operator&lt;&lt;(const char*)
23: note:                 myStream&amp; operator&lt;&lt;(myStream&amp;, myStream&amp; (*)(myStream&amp;))
*/
</code></pre>
<p>Bin für jeden Tip dankbar<br />
tschüß<br />
Troll.Soft</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1905612</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1905612</guid><dc:creator><![CDATA[Troll.Soft]]></dc:creator><pubDate>Tue, 01 Jun 2010 20:51:39 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler im Stream  [gelöst] on Tue, 01 Jun 2010 18:29:39 GMT]]></title><description><![CDATA[<p>Das Problem könnte sein, dass <code>myStream()</code> kein LValue ist und somit für <code>my</code> als Parameter nicht in Frage kommt. Frag mich aber bitte nicht, was den GCC dazu bewegt, den Sachverhalt bei <code>myStream() &lt;&lt; &quot;&quot;</code> anders zu sehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1905617</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1905617</guid><dc:creator><![CDATA[ipsec]]></dc:creator><pubDate>Tue, 01 Jun 2010 18:29:39 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler im Stream  [gelöst] on Tue, 01 Jun 2010 18:40:52 GMT]]></title><description><![CDATA[<p>ipsec schrieb:</p>
<blockquote>
<p>Frag mich aber bitte nicht, was den GCC dazu bewegt, den Sachverhalt bei <code>myStream() &lt;&lt; &quot;&quot;</code> anders zu sehen.</p>
</blockquote>
<p>Man darf temporäre Objekte zwar nicht als nichtkonstante Referenz an eine Funktion übergeben, aber man darf deren non-const Memberfunktionen aufrufen (also auch operator&lt;&lt;(const char*)).<br />
Dass man das const auf diese Weise ganz leicht wegbekommt, war mir gar nicht bewusst... und ob das im Sinne der Erfinder war, weiß ich auch nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1905622</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1905622</guid><dc:creator><![CDATA[Athar]]></dc:creator><pubDate>Tue, 01 Jun 2010 18:40:52 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler im Stream  [gelöst] on Tue, 01 Jun 2010 19:00:14 GMT]]></title><description><![CDATA[<p>Wenn ich den Code so erweitere</p>
<pre><code>ostringstream&amp; my2(ostringstream&amp; stream)	{	stream &lt;&lt; &quot;&lt;my2Stream&gt;&quot;;	return stream;	} 

int main() 
{
	myStream o;
	o &lt;&lt; my;
	o &lt;&lt; &quot;y&quot;;
	o &lt;&lt; &quot;z&quot; &lt;&lt; my;

	myStream() &lt;&lt; &quot;&quot; &lt;&lt; my &lt;&lt; my &lt;&lt; &quot;&quot; &lt;&lt; my;
//	myStream() &lt;&lt; my;
	ostringstream() &lt;&lt; &quot;hicks&quot;;
	ostringstream() &lt;&lt; my;	//	38: warning: the address of 'myStream&amp; my(myStream&amp;)' will always evaluate as 'true'
}
</code></pre>
<p>compiliert der gcc durch, allerdings mit einer Warnung. Irgendwie muß man da doch tricksen können, so das es geht. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
<p>tschüß<br />
Troll.Soft</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1905627</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1905627</guid><dc:creator><![CDATA[Troll.Soft]]></dc:creator><pubDate>Tue, 01 Jun 2010 19:00:14 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler im Stream  [gelöst] on Tue, 01 Jun 2010 19:14:50 GMT]]></title><description><![CDATA[<p>Kannst du schon, du musst operator&lt;&lt;(myStream&amp;(*)(myStream&amp;)) halt nur auch mit in die Klasse nehmen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1905633</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1905633</guid><dc:creator><![CDATA[Athar]]></dc:creator><pubDate>Tue, 01 Jun 2010 19:14:50 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler im Stream  [gelöst] on Tue, 01 Jun 2010 19:38:52 GMT]]></title><description><![CDATA[<p>Athar schrieb:</p>
<blockquote>
<p>Kannst du schon, du musst operator&lt;&lt;(myStream&amp;(*)(myStream&amp;)) halt nur auch mit in die Klasse nehmen.</p>
</blockquote>
<p>Wenn ich diesen Code in die Klasse mit reinnehme</p>
<pre><code>myStream&amp; operator&lt;&lt;(myStream&amp;(*)(myStream&amp;) )	{ o &lt;&lt; &quot;hi fan&quot;;	return *this;	}
</code></pre>
<p>compiliert alles durch und</p>
<pre><code>myStream() &lt;&lt; my;
</code></pre>
<p>liefert den fan aus, aber dann wird dieser Code</p>
<pre><code>myStream o;
	o &lt;&lt; my;
</code></pre>
<p>bemängelt mit</p>
<blockquote>
<p>L:/code/html/main_html_test_stream_iostream/main_html_test_stream_iostream.cpp:34: error: ambiguous overload for 'operator&lt;&lt;' in 'o &lt;&lt; my'</p>
</blockquote>
<p>Brauche weitere Anregungen<br />
tschüß<br />
Troll.Soft</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1905646</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1905646</guid><dc:creator><![CDATA[Troll.Soft]]></dc:creator><pubDate>Tue, 01 Jun 2010 19:38:52 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler im Stream  [gelöst] on Tue, 01 Jun 2010 19:44:16 GMT]]></title><description><![CDATA[<p>Wenn du den operator&lt;&lt; in die Klasse reinnimmst, muss die globale Funktion entsprechend weg.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1905650</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1905650</guid><dc:creator><![CDATA[Athar]]></dc:creator><pubDate>Tue, 01 Jun 2010 19:44:16 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler im Stream  [gelöst] on Tue, 01 Jun 2010 20:51:12 GMT]]></title><description><![CDATA[<p>Athar schrieb:</p>
<blockquote>
<p>Wenn du den operator&lt;&lt; in die Klasse reinnimmst, muss die globale Funktion entsprechend weg.</p>
</blockquote>
<p>Oh je, da hatte ich wohl etwas mißverstanden. Aber juchhe, nach korrekter Ausführung Deines Vorschlages funktioniert es. Hier ist der Code.</p>
<pre><code>#include &lt;sstream&gt; 
#include &lt;iostream&gt;

using namespace std;

class myStream; 
myStream&amp; my(myStream&amp;);

class myStream
{ 
public: 
	myStream()	{} 	
	~myStream()	{	cout &lt;&lt; &quot;  start &quot; &lt;&lt; o.str() &lt;&lt; &quot; ende  &quot;;	} 

	friend myStream&amp; my(myStream&amp; stream)	{	stream.	o &lt;&lt; &quot;&lt;myStream&gt;&quot;;	return stream;	} 
	myStream&amp; operator&lt;&lt;(const char* m)		{			o &lt;&lt; m;				return *this;	}

// manipulator function 
inline myStream&amp; operator&lt;&lt;(myStream&amp; (*function)(myStream&amp;) ) {	return (*function)(*this);	} 

private:
	ostringstream o;
}; 

int main() 
{
	myStream o;
	o &lt;&lt; my;
	o &lt;&lt; &quot;y&quot;;
	o &lt;&lt; &quot;z&quot; &lt;&lt; my;

	myStream() &lt;&lt; &quot;&quot; &lt;&lt; my &lt;&lt; my &lt;&lt; &quot;&quot; &lt;&lt; my;
	myStream() &lt;&lt; my;
}
</code></pre>
<p>danke<br />
Troll.Soft</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1905686</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1905686</guid><dc:creator><![CDATA[Troll.Soft]]></dc:creator><pubDate>Tue, 01 Jun 2010 20:51:12 GMT</pubDate></item></channel></rss>