<?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[Funktionstemplate als friend eines Klassentemplates]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe ein Klassentemplate Det_Manip und möchte das Funktionstemplate</p>
<pre><code class="language-cpp">template&lt;class T&gt; ostream&amp; operator&lt;&lt;(ostream&amp; s, const Bound_Det_Manip&lt;T&gt;&amp; bdm);
</code></pre>
<p>als friend von Det_Manip deklarieren:</p>
<pre><code class="language-cpp">#ifndef TEMP_H_
#define TEMP_H_

...

template&lt;class T&gt; class Bound_Det_Manip;

template&lt;class T&gt; ostream&amp; operator&lt;&lt;(ostream&amp; s, const Bound_Det_Manip&lt;T&gt;&amp; bdm);

template&lt;class T&gt; class Det_Manip
{
	friend ostream&amp; operator&lt;&lt;&lt;T&gt;(ostream&amp; s, const Bound_Det_Manip&lt;T&gt;&amp; bdm);
private:
	int m_level;
public:
	explicit Det_Manip(int level) : m_level(level) { }
	Bound_Det_Manip&lt;T&gt; operator()(const T* n) const;
};

template&lt;class T&gt; class Bound_Det_Manip
{
	...
};

...

#endif
</code></pre>
<p>Das kompiliert so ohne Warnmeldungen auszugeben. Wenn ich allerdings in Zeile 14</p>
<pre><code class="language-cpp">friend ostream&amp; operator&lt;&lt;&lt;T&gt;(ostream&amp; s, const Bound_Det_Manip&lt;T&gt;&amp; bdm);
</code></pre>
<p>durch</p>
<pre><code class="language-cpp">friend ostream&amp; ::operator&lt;&lt;(ostream&amp; s, const Bound_Det_Manip&lt;T&gt;&amp; bdm);
</code></pre>
<p>ersetze, erhalte ich die Compilermeldung</p>
<blockquote>
<p>../src/temp.h:18: warning: friend declaration ‘std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, const Bound_Det_Manip&lt;T&gt;&amp;)’ declares a non-template function<br />
../src/temp.h:18: warning: (if this is not what you intended, make sure the function template has already been declared and add &lt;&gt; after the function name here) -Wno-non-template-friend disables this warning</p>
</blockquote>
<p>und das Programm macht dasselbe wie vorher.</p>
<p>Trotz Lektüre von 8.4.1 &quot;Friend Functions&quot; des Josuttis (C++ Templates) verstehe ich nicht, was hier das Problem ist. Kann das jemand erklären?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/226248/funktionstemplate-als-friend-eines-klassentemplates</link><generator>RSS for Node</generator><lastBuildDate>Thu, 01 Oct 2026 01:17:48 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/226248.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 30 Oct 2008 21:57:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Funktionstemplate als friend eines Klassentemplates on Thu, 30 Oct 2008 21:57:36 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe ein Klassentemplate Det_Manip und möchte das Funktionstemplate</p>
<pre><code class="language-cpp">template&lt;class T&gt; ostream&amp; operator&lt;&lt;(ostream&amp; s, const Bound_Det_Manip&lt;T&gt;&amp; bdm);
</code></pre>
<p>als friend von Det_Manip deklarieren:</p>
<pre><code class="language-cpp">#ifndef TEMP_H_
#define TEMP_H_

...

template&lt;class T&gt; class Bound_Det_Manip;

template&lt;class T&gt; ostream&amp; operator&lt;&lt;(ostream&amp; s, const Bound_Det_Manip&lt;T&gt;&amp; bdm);

template&lt;class T&gt; class Det_Manip
{
	friend ostream&amp; operator&lt;&lt;&lt;T&gt;(ostream&amp; s, const Bound_Det_Manip&lt;T&gt;&amp; bdm);
private:
	int m_level;
public:
	explicit Det_Manip(int level) : m_level(level) { }
	Bound_Det_Manip&lt;T&gt; operator()(const T* n) const;
};

template&lt;class T&gt; class Bound_Det_Manip
{
	...
};

...

#endif
</code></pre>
<p>Das kompiliert so ohne Warnmeldungen auszugeben. Wenn ich allerdings in Zeile 14</p>
<pre><code class="language-cpp">friend ostream&amp; operator&lt;&lt;&lt;T&gt;(ostream&amp; s, const Bound_Det_Manip&lt;T&gt;&amp; bdm);
</code></pre>
<p>durch</p>
<pre><code class="language-cpp">friend ostream&amp; ::operator&lt;&lt;(ostream&amp; s, const Bound_Det_Manip&lt;T&gt;&amp; bdm);
</code></pre>
<p>ersetze, erhalte ich die Compilermeldung</p>
<blockquote>
<p>../src/temp.h:18: warning: friend declaration ‘std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, const Bound_Det_Manip&lt;T&gt;&amp;)’ declares a non-template function<br />
../src/temp.h:18: warning: (if this is not what you intended, make sure the function template has already been declared and add &lt;&gt; after the function name here) -Wno-non-template-friend disables this warning</p>
</blockquote>
<p>und das Programm macht dasselbe wie vorher.</p>
<p>Trotz Lektüre von 8.4.1 &quot;Friend Functions&quot; des Josuttis (C++ Templates) verstehe ich nicht, was hier das Problem ist. Kann das jemand erklären?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1607540</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1607540</guid><dc:creator><![CDATA[ingobulla]]></dc:creator><pubDate>Thu, 30 Oct 2008 21:57:36 GMT</pubDate></item></channel></rss>