<?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[Kollision zwischen &amp;lt;&amp;lt;-Operatoren in Namespaces]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich verwende eine Templatefunktion</p>
<pre><code>template&lt;class K, class V&gt; ostream&amp; operator&lt;&lt;(ostream&amp; s, const map&lt;K, V&gt;&amp; mp)
{
	for (typename map&lt;K, V&gt;::const_iterator it = mp.begin(); it != mp.end(); ++it)
		s &lt;&lt; (*it).first &lt;&lt; &quot; =&gt; &quot; &lt;&lt; (*it).second &lt;&lt; &quot;   &quot;;
	return s;
}
</code></pre>
<p>um Maps mittels des Operators &lt;&lt; ausgeben zu können. Das hat bisher insoweit funktioniert, bei der Verwendung von Namespaces ist jedoch folgendes Problem aufgetaucht: Wenn ich</p>
<pre><code>class In_Out_Streams
{
	friend ostream&amp; operator&lt;&lt;(ostream&amp; s, In_Out_Streams&amp; ios);
	...
};
</code></pre>
<p>in einen Namespace IO setze, so erhalte ich dann beim Kompilieren von</p>
<pre><code>namespace IO {
	void f()
	{
		map&lt;string, string&gt; dirs;
		cout &lt;&lt; dirs &lt;&lt; endl;   // FEHLER
	}
}
</code></pre>
<p>die Fehlermeldung</p>
<pre><code>Building file: ../src/IO/files.cpp
Invoking: GCC C++ Compiler
g++ -I../../../boost -I../../../gsl/include -I../../../log4cxx/src/main/include -I../ -I../src -I../src/classification -I../src/IO -I../src/node -I../src/tree -O0 -g3 -c -fmessage-length=0 -ansi -MMD -MP -MF&quot;src/IO/files.d&quot; -MT&quot;src/IO/files.d&quot; -o&quot;src/IO/files.o&quot; &quot;../src/IO/files.cpp&quot;
../src/IO/files.cpp: In function ‘void IO::f()’:
../src/IO/files.cpp:350: error: no match for ‘operator&lt;&lt;’ in ‘std::cout &lt;&lt; dirs’
/usr/include/c++/4.1.2/bits/ostream.tcc:67: note: candidates are: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp; (*)(std::basic_ostream&lt;_CharT, _Traits&gt;&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:78: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::basic_ios&lt;_CharT, _Traits&gt;&amp; (*)(std::basic_ios&lt;_CharT, _Traits&gt;&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:90: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::ios_base&amp; (*)(std::ios_base&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:241: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:264: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:102: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(bool) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:125: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(short int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:157: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(short unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:183: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:215: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:288: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long long int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:311: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long long unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:361: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(double) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:335: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(float) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:384: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long double) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:407: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(const void*) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:430: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::basic_streambuf&lt;_CharT, _Traits&gt;*) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
../src/IO/files.cpp:316: note:                 std::ostream&amp; IO::operator&lt;&lt;(std::ostream&amp;, IO::In_Out_Streams&amp;)
make: *** [src/IO/files.o] Error 1
</code></pre>
<p>Wenn ich f in einen anderen Namespace setze oder keinen Left-Shift-Operator für In_Out_Streams definiere, taucht das Problem nicht auf.</p>
<p>Weiss jemand, was hier los ist und wie man es behebt?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/238950/kollision-zwischen-lt-lt-operatoren-in-namespaces</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 16:26:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/238950.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 17 Apr 2009 15:20:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Kollision zwischen &amp;lt;&amp;lt;-Operatoren in Namespaces on Fri, 17 Apr 2009 15:20:23 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich verwende eine Templatefunktion</p>
<pre><code>template&lt;class K, class V&gt; ostream&amp; operator&lt;&lt;(ostream&amp; s, const map&lt;K, V&gt;&amp; mp)
{
	for (typename map&lt;K, V&gt;::const_iterator it = mp.begin(); it != mp.end(); ++it)
		s &lt;&lt; (*it).first &lt;&lt; &quot; =&gt; &quot; &lt;&lt; (*it).second &lt;&lt; &quot;   &quot;;
	return s;
}
</code></pre>
<p>um Maps mittels des Operators &lt;&lt; ausgeben zu können. Das hat bisher insoweit funktioniert, bei der Verwendung von Namespaces ist jedoch folgendes Problem aufgetaucht: Wenn ich</p>
<pre><code>class In_Out_Streams
{
	friend ostream&amp; operator&lt;&lt;(ostream&amp; s, In_Out_Streams&amp; ios);
	...
};
</code></pre>
<p>in einen Namespace IO setze, so erhalte ich dann beim Kompilieren von</p>
<pre><code>namespace IO {
	void f()
	{
		map&lt;string, string&gt; dirs;
		cout &lt;&lt; dirs &lt;&lt; endl;   // FEHLER
	}
}
</code></pre>
<p>die Fehlermeldung</p>
<pre><code>Building file: ../src/IO/files.cpp
Invoking: GCC C++ Compiler
g++ -I../../../boost -I../../../gsl/include -I../../../log4cxx/src/main/include -I../ -I../src -I../src/classification -I../src/IO -I../src/node -I../src/tree -O0 -g3 -c -fmessage-length=0 -ansi -MMD -MP -MF&quot;src/IO/files.d&quot; -MT&quot;src/IO/files.d&quot; -o&quot;src/IO/files.o&quot; &quot;../src/IO/files.cpp&quot;
../src/IO/files.cpp: In function ‘void IO::f()’:
../src/IO/files.cpp:350: error: no match for ‘operator&lt;&lt;’ in ‘std::cout &lt;&lt; dirs’
/usr/include/c++/4.1.2/bits/ostream.tcc:67: note: candidates are: std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp; (*)(std::basic_ostream&lt;_CharT, _Traits&gt;&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:78: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::basic_ios&lt;_CharT, _Traits&gt;&amp; (*)(std::basic_ios&lt;_CharT, _Traits&gt;&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:90: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::ios_base&amp; (*)(std::ios_base&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:241: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:264: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:102: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(bool) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:125: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(short int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:157: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(short unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:183: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:215: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:288: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long long int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:311: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long long unsigned int) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:361: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(double) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:335: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(float) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:384: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(long double) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:407: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(const void*) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
/usr/include/c++/4.1.2/bits/ostream.tcc:430: note:                 std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::basic_ostream&lt;_CharT, _Traits&gt;::operator&lt;&lt;(std::basic_streambuf&lt;_CharT, _Traits&gt;*) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;]
../src/IO/files.cpp:316: note:                 std::ostream&amp; IO::operator&lt;&lt;(std::ostream&amp;, IO::In_Out_Streams&amp;)
make: *** [src/IO/files.o] Error 1
</code></pre>
<p>Wenn ich f in einen anderen Namespace setze oder keinen Left-Shift-Operator für In_Out_Streams definiere, taucht das Problem nicht auf.</p>
<p>Weiss jemand, was hier los ist und wie man es behebt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1697339</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1697339</guid><dc:creator><![CDATA[ingobulla]]></dc:creator><pubDate>Fri, 17 Apr 2009 15:20:23 GMT</pubDate></item></channel></rss>