<?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[typedef aus Templateklassen als friend]]></title><description><![CDATA[<p>Mich würde mal interessieren, was davon richtig ist bzw. ob überhaupt:</p>
<pre><code class="language-cpp">struct X {};
struct Y {};

template &lt;typename T, class U&gt;
class Foo
{
    //...
};

template &lt;typename T&gt;
class Bar
{
public:
    typedef Foo&lt;T, X&gt; XFoo;
    typedef Foo&lt;T, Y&gt; YFoo;
};

template &lt;typename T&gt;
class FooNeedsAccess
{
    friend class Bar&lt;T&gt;::Xfoo;
    friend class Bar&lt;T&gt;::YFoo;
};
</code></pre>
<p>Das nimmt der gcc-Compiler. Wenn ich das aber dem Visual Studio-Compiler zu fressen gebe, dann meckert er. Er möchte das lieber so:</p>
<pre><code class="language-cpp">//... Wie oben
template &lt;typename T&gt;
class FooNeedsAccess
{
    friend typename Bar&lt;T&gt;::Xfoo;
    friend typename Bar&lt;T&gt;::YFoo;
};
</code></pre>
<p>Was ist denn nun davon richtig/bzw. überhaupt erlaubt. Im Standard hab ich nur gefunden, dass man keine Template-Parameter als friend benutzen darf D.h.:</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
class Foo
{
    friend class T;
};
</code></pre>
<p>PS: Ich weiß, dass es bessere Lösungen gibt, aber ich bin da irgendwie drüber gestolpert :p</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/173806/typedef-aus-templateklassen-als-friend</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 11:13:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/173806.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 20 Feb 2007 07:35:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to typedef aus Templateklassen als friend on Tue, 20 Feb 2007 07:35:34 GMT]]></title><description><![CDATA[<p>Mich würde mal interessieren, was davon richtig ist bzw. ob überhaupt:</p>
<pre><code class="language-cpp">struct X {};
struct Y {};

template &lt;typename T, class U&gt;
class Foo
{
    //...
};

template &lt;typename T&gt;
class Bar
{
public:
    typedef Foo&lt;T, X&gt; XFoo;
    typedef Foo&lt;T, Y&gt; YFoo;
};

template &lt;typename T&gt;
class FooNeedsAccess
{
    friend class Bar&lt;T&gt;::Xfoo;
    friend class Bar&lt;T&gt;::YFoo;
};
</code></pre>
<p>Das nimmt der gcc-Compiler. Wenn ich das aber dem Visual Studio-Compiler zu fressen gebe, dann meckert er. Er möchte das lieber so:</p>
<pre><code class="language-cpp">//... Wie oben
template &lt;typename T&gt;
class FooNeedsAccess
{
    friend typename Bar&lt;T&gt;::Xfoo;
    friend typename Bar&lt;T&gt;::YFoo;
};
</code></pre>
<p>Was ist denn nun davon richtig/bzw. überhaupt erlaubt. Im Standard hab ich nur gefunden, dass man keine Template-Parameter als friend benutzen darf D.h.:</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
class Foo
{
    friend class T;
};
</code></pre>
<p>PS: Ich weiß, dass es bessere Lösungen gibt, aber ich bin da irgendwie drüber gestolpert :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1231653</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231653</guid><dc:creator><![CDATA[viande]]></dc:creator><pubDate>Tue, 20 Feb 2007 07:35:34 GMT</pubDate></item><item><title><![CDATA[Reply to typedef aus Templateklassen als friend on Tue, 20 Feb 2007 13:55:54 GMT]]></title><description><![CDATA[<p>viande schrieb:</p>
<blockquote>
<p>Mich würde mal interessieren, was davon richtig ist bzw. ob überhaupt:</p>
</blockquote>
<p>Keines ist richtig. typedefs sind in einer friend-Deklaration nicht erlaubt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1231973</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231973</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Tue, 20 Feb 2007 13:55:54 GMT</pubDate></item><item><title><![CDATA[Reply to typedef aus Templateklassen als friend on Tue, 20 Feb 2007 17:13:33 GMT]]></title><description><![CDATA[<p>Gut, das habe ich mir schon fast gedacht. War eh nur Faulheit, sind aber schon verbannt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1232130</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1232130</guid><dc:creator><![CDATA[viande]]></dc:creator><pubDate>Tue, 20 Feb 2007 17:13:33 GMT</pubDate></item></channel></rss>