<?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[friend function im template]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe zwei templates:</p>
<pre><code class="language-cpp">template &lt;class X&gt; class node{
public:	        friend void add(X* obj);
private:	node(X* content);
		X* content;
};

template&lt;class X&gt;class vector{
public:		void add(X* obj);	
private:	node&lt;X&gt;*first;

};
</code></pre>
<p>Ich möchte, dass nur innerhalb der Funktion add(X* obj) von vector ein neues objekt der klasse node erstellt werden kann.<br />
Deshalb hab ich den Konstruktor von node private gesetzt.<br />
Wenn ich jedoch kompiliere, kommt folgender Fehler:</p>
<p>..\main.cpp:22: instantiated from here<br />
..\node.h:42: error: `node&lt;X&gt;::node(X*, int) [with X = Autos]' is private<br />
..\vector.h:56: error: within this context</p>
<p>Ich dachte, innnerhlab der friendfunction kann ich auf alle privaten attribute zugreifen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/275122/friend-function-im-template</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 07:55:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/275122.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 09 Oct 2010 15:14:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to friend function im template on Sat, 09 Oct 2010 15:14:37 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe zwei templates:</p>
<pre><code class="language-cpp">template &lt;class X&gt; class node{
public:	        friend void add(X* obj);
private:	node(X* content);
		X* content;
};

template&lt;class X&gt;class vector{
public:		void add(X* obj);	
private:	node&lt;X&gt;*first;

};
</code></pre>
<p>Ich möchte, dass nur innerhalb der Funktion add(X* obj) von vector ein neues objekt der klasse node erstellt werden kann.<br />
Deshalb hab ich den Konstruktor von node private gesetzt.<br />
Wenn ich jedoch kompiliere, kommt folgender Fehler:</p>
<p>..\main.cpp:22: instantiated from here<br />
..\node.h:42: error: `node&lt;X&gt;::node(X*, int) [with X = Autos]' is private<br />
..\vector.h:56: error: within this context</p>
<p>Ich dachte, innnerhlab der friendfunction kann ich auf alle privaten attribute zugreifen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1963330</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1963330</guid><dc:creator><![CDATA[invoices]]></dc:creator><pubDate>Sat, 09 Oct 2010 15:14:37 GMT</pubDate></item><item><title><![CDATA[Reply to friend function im template on Sun, 10 Oct 2010 08:17:24 GMT]]></title><description><![CDATA[<p>Du hast kein friend auf vector::add definiert sondern auf eine Funktion add im globalen Namensraum.</p>
<p>Für Deine Vektor Klasse ist Node immer noch private.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1963453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1963453</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Sun, 10 Oct 2010 08:17:24 GMT</pubDate></item><item><title><![CDATA[Reply to friend function im template on Sun, 10 Oct 2010 08:46:47 GMT]]></title><description><![CDATA[<p>muss dann die friendzeile folgendermaßen aussehen:</p>
<pre><code class="language-cpp">friend void vector&lt;X&gt;::add(X* obj);
</code></pre>
<p>dann bekomme ich aber folgenden fehler</p>
<p>..\node.h:15: error: variable or field <code>vector' declared void ..\\node.h:15: error:</code>vector' is neither function nor member function; cannot be declared friend<br />
..\node.h:15: error: expected `;' before '&lt;' token</p>
<p>Das Template node kennt ja mein Template vector nicht...<br />
Also hab ich gedacht, ich schreib noch folgendes in die node.h datei:<br />
#include &quot;vector.h&quot;<br />
Hat leider auch nicht geholfen. :S<br />
was mache ich falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1963461</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1963461</guid><dc:creator><![CDATA[invoices]]></dc:creator><pubDate>Sun, 10 Oct 2010 08:46:47 GMT</pubDate></item><item><title><![CDATA[Reply to friend function im template on Sun, 10 Oct 2010 15:36:49 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile-var-mode-is-viewprofile-and-u-is-100590.html" rel="nofollow">Martin Richter</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-1.html" rel="nofollow">MFC (Visual C++)</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-15.html" rel="nofollow">C++</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39405.html" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1963563</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1963563</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Sun, 10 Oct 2010 15:36:49 GMT</pubDate></item></channel></rss>