<?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[Deklaration eines friend-Operators zwischen Templates]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe ein Matrix-Klasse und eine Vector-Klasse (beide Templates), und moechte einen Multiplations-operator zwischen beiden definieren. Bisher habe ich mit MS VC 6.0 und gcc 3.3 gearbeitet und hatte eine unbefriedigende Loesung:</p>
<pre><code class="language-cpp">#ifdef WIN32
    friend Vector&lt;T&gt; operator* (const Matrix&lt;T&gt;&amp; m, const Vector&lt;T&gt;&amp; v);    
    friend Vector&lt;T&gt; operator* (const Vector&lt;T&gt;&amp; v, const Matrix&lt;T&gt;&amp; m);    
#else
    friend Vector&lt;T&gt; operator*&lt;T&gt; (const Matrix&lt;T&gt;&amp; m, const Vector&lt;T&gt;&amp; v);        
    friend Vector&lt;T&gt; operator*&lt;T&gt; (const Vector&lt;T&gt;&amp; v, const Matrix&lt;T&gt;&amp; m);        
#endif
</code></pre>
<p>Jetzt bin ich auf gcc 4.0 umgestiegen und von den obigen Versionen wird keine mehr genommen. Die obere Version liefert die Warnung</p>
<p>Vector.h:88: warning: friend declaration ‘Vector&lt;T&gt; operator*(const Matrix&lt;T&gt;&amp;, const Vector&lt;T&gt;&amp;)’ declares a non-template function<br />
Vector.h:88: 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<br />
Vector.h:89: warning: friend declaration ‘Vector&lt;T&gt; operator*(const Vector&lt;T&gt;&amp;, const Matrix&lt;T&gt;&amp;)’ declares a non-template function</p>
<p>die untere Version den Fehler<br />
Vector.h:91: error: declaration of ‘operator*’ as non-function<br />
Vector.h:91: error: expected ‘;’ before ‘&lt;’ token<br />
Vector.h:92: error: declaration of ‘operator*’ as non-function<br />
Vector.h:92: error: expected ‘;’ before ‘&lt;’ token</p>
<p>Jetzt Frage ich mich: gibt es denn eine voellig standard-komforme Version die ueberall ohne Fehler oder Warnung laeuft?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/137444/deklaration-eines-friend-operators-zwischen-templates</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 18:39:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/137444.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 17 Feb 2006 13:22:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Deklaration eines friend-Operators zwischen Templates on Fri, 17 Feb 2006 13:22:08 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe ein Matrix-Klasse und eine Vector-Klasse (beide Templates), und moechte einen Multiplations-operator zwischen beiden definieren. Bisher habe ich mit MS VC 6.0 und gcc 3.3 gearbeitet und hatte eine unbefriedigende Loesung:</p>
<pre><code class="language-cpp">#ifdef WIN32
    friend Vector&lt;T&gt; operator* (const Matrix&lt;T&gt;&amp; m, const Vector&lt;T&gt;&amp; v);    
    friend Vector&lt;T&gt; operator* (const Vector&lt;T&gt;&amp; v, const Matrix&lt;T&gt;&amp; m);    
#else
    friend Vector&lt;T&gt; operator*&lt;T&gt; (const Matrix&lt;T&gt;&amp; m, const Vector&lt;T&gt;&amp; v);        
    friend Vector&lt;T&gt; operator*&lt;T&gt; (const Vector&lt;T&gt;&amp; v, const Matrix&lt;T&gt;&amp; m);        
#endif
</code></pre>
<p>Jetzt bin ich auf gcc 4.0 umgestiegen und von den obigen Versionen wird keine mehr genommen. Die obere Version liefert die Warnung</p>
<p>Vector.h:88: warning: friend declaration ‘Vector&lt;T&gt; operator*(const Matrix&lt;T&gt;&amp;, const Vector&lt;T&gt;&amp;)’ declares a non-template function<br />
Vector.h:88: 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<br />
Vector.h:89: warning: friend declaration ‘Vector&lt;T&gt; operator*(const Vector&lt;T&gt;&amp;, const Matrix&lt;T&gt;&amp;)’ declares a non-template function</p>
<p>die untere Version den Fehler<br />
Vector.h:91: error: declaration of ‘operator*’ as non-function<br />
Vector.h:91: error: expected ‘;’ before ‘&lt;’ token<br />
Vector.h:92: error: declaration of ‘operator*’ as non-function<br />
Vector.h:92: error: expected ‘;’ before ‘&lt;’ token</p>
<p>Jetzt Frage ich mich: gibt es denn eine voellig standard-komforme Version die ueberall ohne Fehler oder Warnung laeuft?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/996698</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/996698</guid><dc:creator><![CDATA[mada-cip]]></dc:creator><pubDate>Fri, 17 Feb 2006 13:22:08 GMT</pubDate></item><item><title><![CDATA[Reply to Deklaration eines friend-Operators zwischen Templates on Fri, 17 Feb 2006 13:42:19 GMT]]></title><description><![CDATA[<p>Versuch mal</p>
<pre><code class="language-cpp">friend Vector&lt;T&gt; operator*&lt;&gt;(...);
</code></pre>
<p>Ach, ich vergass: friend Deklaration ist keine gültige Vorwärts-Deklaration nach Standard (und GCC 4 hält sich dran). IMHO muss beim Auftauchen der friend Deklaration bereits</p>
<pre><code class="language-cpp">template&lt;class T&gt;
Vector&lt;T&gt; operator*(const Vector&lt;T&gt;&amp;, const Matrix&lt;T&gt;&amp;);
</code></pre>
<p>bekannt sein...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/996723</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/996723</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Fri, 17 Feb 2006 13:42:19 GMT</pubDate></item><item><title><![CDATA[Reply to Deklaration eines friend-Operators zwischen Templates on Fri, 17 Feb 2006 13:51:43 GMT]]></title><description><![CDATA[<p>evtl.</p>
<pre><code class="language-cpp">template&lt;typename T&gt; class Vector;
template&lt;typename T&gt; class Matrix;

template&lt;typename T&gt; Vector&lt;T&gt; operator* (const Vector&lt;T&gt;&amp; lhs, const Matrix&lt;T&gt;&amp; rhs);
template&lt;typename T&gt; Vector&lt;T&gt; operator* (const Matrix&lt;T&gt;&amp; lhs, const Vector&lt;T&gt;&amp; rhs);

template&lt;typename T&gt; class Vector
{
	friend Vector&lt;T&gt; operator*&lt;&gt; (const Vector&lt;T&gt;&amp; lhs, const Matrix&lt;T&gt;&amp; rhs);
	friend Vector&lt;T&gt; operator*&lt;&gt; (const Matrix&lt;T&gt;&amp; lhs, const Vector&lt;T&gt;&amp; rhs);
};

template&lt;typename T&gt; class Matrix
{
	friend Vector&lt;T&gt; operator*&lt;&gt; (const Vector&lt;T&gt;&amp; lhs, const Matrix&lt;T&gt;&amp; rhs);
	friend Vector&lt;T&gt; operator*&lt;&gt; (const Matrix&lt;T&gt;&amp; lhs, const Vector&lt;T&gt;&amp; rhs);
};
</code></pre>
<p>wenn ms vc 6.0 etwas nicht annimmt, hat das häufig genug nichts mit fehlerhaften code zu tun...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/996734</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/996734</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Fri, 17 Feb 2006 13:51:43 GMT</pubDate></item><item><title><![CDATA[Reply to Deklaration eines friend-Operators zwischen Templates on Fri, 17 Feb 2006 16:08:40 GMT]]></title><description><![CDATA[<p>Guckst du hier:<br />
<a href="http://www.cuj.com/documents/s=8244/cujcexp2101sutter/" rel="nofollow">http://www.cuj.com/documents/s=8244/cujcexp2101sutter/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/996843</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/996843</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Fri, 17 Feb 2006 16:08:40 GMT</pubDate></item><item><title><![CDATA[Reply to Deklaration eines friend-Operators zwischen Templates on Sat, 18 Feb 2006 09:49:14 GMT]]></title><description><![CDATA[<p>Vielen Dank erstmal,</p>
<p>funktioniert aber trotzdem nicht.</p>
<pre><code class="language-cpp">friend Vector&lt;T&gt; operator*&lt;&gt; (const Vector&lt;T&gt;&amp; lhs, const Matrix&lt;T&gt;&amp; rhs);
    friend Vector&lt;T&gt; operator*&lt;&gt; (const Matrix&lt;T&gt;&amp; lhs, const Vector&lt;T&gt;&amp; rhs);
</code></pre>
<p>führt leider zur Fehlermeldung</p>
<p>Vector.h:91: error: declaration of ‘operator*’ as non-function<br />
Vector.h:91: error: expected ‘;’ before ‘&lt;’ token</p>
<p>die Version</p>
<pre><code class="language-cpp">friend Vector&lt;T&gt; operator*&lt;T&gt; (const Vector&lt;T&gt;&amp; lhs, const Matrix&lt;T&gt;&amp; rhs);
    friend Vector&lt;T&gt; operator*&lt;T&gt; (const Matrix&lt;T&gt;&amp; lhs, const Vector&lt;T&gt;&amp; rhs);
</code></pre>
<p>bingt übrigens denselben Fehler <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/997109</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/997109</guid><dc:creator><![CDATA[mada-cip]]></dc:creator><pubDate>Sat, 18 Feb 2006 09:49:14 GMT</pubDate></item></channel></rss>