<?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[standardkonforme friend template funktionen]]></title><description><![CDATA[<p>Ich habe gestern ein altes Projekt rausgekramt, daß ich noch mit dem <a href="http://MSVC.NET" rel="nofollow">MSVC.NET</a> (VC7.0) erzeugt hatte (und dort auch läuft).</p>
<p>Jetzt bei Verwendung des <a href="http://MSVC.NET" rel="nofollow">MSVC.NET</a> 2003 (VC7.1) erzeugt mir der Compiler (bzw. der Linker) jedoch einige Fehlermeldungen.</p>
<p>Ich habe eine template-Klasse 'd_array' und eine Test-Funktion dazu geschrieben, welche als friend deklariert sein soll, damit sie auf interne (private) Member zugreifen kann. Sie steht extra in einer anderen Datei.</p>
<p>Hier die Testfunktion(en):</p>
<pre><code class="language-cpp">template &lt;typename T, unsigned short N&gt;
void test_d_array(const d_array&lt;T, N&gt;&amp; array)
{
	cout &lt;&lt; &quot;Array&quot; &lt;&lt; N &lt;&lt; &quot;:&quot; &lt;&lt; endl;
	for(int i=0; i&lt;N; i++)
		cout &lt;&lt; array.st_offsets[i] &lt;&lt; endl;
	cout &lt;&lt; &quot;Size: &quot; &lt;&lt; array.size &lt;&lt; endl;

	for(int y=0; y &lt; N; y++)
	{
		for(int x=0; x &lt; N; x++)
			cout &lt;&lt; (array.check(x, y)? 'O' : 'X');
		cout &lt;&lt; endl;
	}

	cout &lt;&lt; endl;
}

void test_d_arrays()
{
	typedef d_array&lt;int, 8&gt; Array8;
	Array8 array8;

	test_d_array(array8);

	typedef d_array&lt;int, 7&gt; Array7;
	Array7 array7;

	test_d_array(array7);
}
</code></pre>
<p>Und hier die Template-Klasse:</p>
<pre><code class="language-cpp">template &lt;typename T, unsigned short N&gt;
class d_array
{
public:
     // ...

private:
	friend void test_d_array(const d_array&lt;T, N&gt;&amp; array); // for tests

    // member
    enum { size = (N%2==0)? (N+2)*N/2 : (N*N+1)/2, M = (N+1)/2 };

    ...
};
</code></pre>
<p>Der Linker erkennt nun nicht mehr die Template Funktion 'test_d_array(...)', welche in der Funktion 'test_d_arrays()' aufgerufen werden.</p>
<p>Wo ist mein (Denk-) Fehler?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/165186/standardkonforme-friend-template-funktionen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 05:43:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/165186.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 16 Nov 2006 11:34:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to standardkonforme friend template funktionen on Thu, 16 Nov 2006 11:34:25 GMT]]></title><description><![CDATA[<p>Ich habe gestern ein altes Projekt rausgekramt, daß ich noch mit dem <a href="http://MSVC.NET" rel="nofollow">MSVC.NET</a> (VC7.0) erzeugt hatte (und dort auch läuft).</p>
<p>Jetzt bei Verwendung des <a href="http://MSVC.NET" rel="nofollow">MSVC.NET</a> 2003 (VC7.1) erzeugt mir der Compiler (bzw. der Linker) jedoch einige Fehlermeldungen.</p>
<p>Ich habe eine template-Klasse 'd_array' und eine Test-Funktion dazu geschrieben, welche als friend deklariert sein soll, damit sie auf interne (private) Member zugreifen kann. Sie steht extra in einer anderen Datei.</p>
<p>Hier die Testfunktion(en):</p>
<pre><code class="language-cpp">template &lt;typename T, unsigned short N&gt;
void test_d_array(const d_array&lt;T, N&gt;&amp; array)
{
	cout &lt;&lt; &quot;Array&quot; &lt;&lt; N &lt;&lt; &quot;:&quot; &lt;&lt; endl;
	for(int i=0; i&lt;N; i++)
		cout &lt;&lt; array.st_offsets[i] &lt;&lt; endl;
	cout &lt;&lt; &quot;Size: &quot; &lt;&lt; array.size &lt;&lt; endl;

	for(int y=0; y &lt; N; y++)
	{
		for(int x=0; x &lt; N; x++)
			cout &lt;&lt; (array.check(x, y)? 'O' : 'X');
		cout &lt;&lt; endl;
	}

	cout &lt;&lt; endl;
}

void test_d_arrays()
{
	typedef d_array&lt;int, 8&gt; Array8;
	Array8 array8;

	test_d_array(array8);

	typedef d_array&lt;int, 7&gt; Array7;
	Array7 array7;

	test_d_array(array7);
}
</code></pre>
<p>Und hier die Template-Klasse:</p>
<pre><code class="language-cpp">template &lt;typename T, unsigned short N&gt;
class d_array
{
public:
     // ...

private:
	friend void test_d_array(const d_array&lt;T, N&gt;&amp; array); // for tests

    // member
    enum { size = (N%2==0)? (N+2)*N/2 : (N*N+1)/2, M = (N+1)/2 };

    ...
};
</code></pre>
<p>Der Linker erkennt nun nicht mehr die Template Funktion 'test_d_array(...)', welche in der Funktion 'test_d_arrays()' aufgerufen werden.</p>
<p>Wo ist mein (Denk-) Fehler?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1175856</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1175856</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Thu, 16 Nov 2006 11:34:25 GMT</pubDate></item><item><title><![CDATA[Reply to standardkonforme friend template funktionen on Thu, 16 Nov 2006 11:40:25 GMT]]></title><description><![CDATA[<p>Th schrieb:</p>
<blockquote>
<p>Sie steht extra in einer anderen Datei.</p>
</blockquote>
<p>Das dürfte (imho) der Fehler sein. Du mußt der Klasse vermutlich einen Prototyp vorgeben, bevor du deine Klasse definierst. Oder du mußt dem Compiler zumindest sagen, daß er es hier mit einer Template-Funktion zu tun hat:</p>
<pre><code class="language-cpp">template&lt;&gt; friend void test_d_array(const d_array&lt;T, N&gt;&amp; array); // for tests
</code></pre>
<p>(oder so ähnlich - den genauen Syntax habe ich nicht im Kopf, weil ich ihn noch nie verwendet habe)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1175861</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1175861</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 16 Nov 2006 11:40:25 GMT</pubDate></item><item><title><![CDATA[Reply to standardkonforme friend template funktionen on Thu, 16 Nov 2006 12:17:54 GMT]]></title><description><![CDATA[<p>Danke für den Tip.</p>
<p>Nach einigem Ausprobieren hier nun die Lösung:<br />
(wichtig war das Einfügen von &lt;T, N&gt; bei der friend Deklaration !!!)</p>
<pre><code class="language-cpp">template &lt;typename T, unsigned short N&gt; class d_array; // forward declaration to class

template &lt;typename T, unsigned short N&gt;
void test_d_array(const d_array&lt;T, N&gt;&amp; array); // declaration of test function

template &lt;typename T, unsigned short N&gt;
class d_array
{
public:
     // ...

private:
    friend void test_d_array&lt;T, N&gt;(const d_array&lt;T, N&gt;&amp; array); // for tests

    // member
    enum { size = (N%2==0)? (N+2)*N/2 : (N*N+1)/2, M = (N+1)/2 };

    ...
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1175896</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1175896</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Thu, 16 Nov 2006 12:17:54 GMT</pubDate></item></channel></rss>