<?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[Verschachtelte Klassen in Templateklassen]]></title><description><![CDATA[<p>Hallo!<br />
Ich beschäftige mich gerade mit Templates und habe folgendes versucht:</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
class A {
public:
    class SubType { };

};

template &lt;typename U&gt;
void foo(typename A&lt;U&gt;::SubType&amp; t);

int main()
{
    A&lt;int&gt;::SubType t;

    foo(t);
    return 0;
}

template &lt;typename U&gt;
void foo(typename A&lt;U&gt;::SubType&amp; t)
{
...
}
</code></pre>
<p>Der Intel C++ Compiler gibt folgendes aus:<br />
error: no instance of function template &quot;foo&quot; matches the argument list<br />
argument types are: (A&lt;int&gt;::SubType)<br />
foo(t);<br />
^</p>
<p>G++ liefert folgendes:<br />
error: no matching function for call to ‘foo(A&lt;int&gt;::SubType&amp;)’</p>
<p>Wenn ich &quot;typename&quot; in der Funktionssignatur weglasse, dann meint der Intel C++ Compiler, dass foo weder eine Funktion noch ein statisches Member sei.</p>
<p>Was ist das Problem?</p>
<p>Grüße,<br />
Kevin</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/290990/verschachtelte-klassen-in-templateklassen</link><generator>RSS for Node</generator><lastBuildDate>Tue, 18 Aug 2026 00:27:14 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/290990.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 08 Aug 2011 15:11:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Verschachtelte Klassen in Templateklassen on Mon, 08 Aug 2011 15:11:37 GMT]]></title><description><![CDATA[<p>Hallo!<br />
Ich beschäftige mich gerade mit Templates und habe folgendes versucht:</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
class A {
public:
    class SubType { };

};

template &lt;typename U&gt;
void foo(typename A&lt;U&gt;::SubType&amp; t);

int main()
{
    A&lt;int&gt;::SubType t;

    foo(t);
    return 0;
}

template &lt;typename U&gt;
void foo(typename A&lt;U&gt;::SubType&amp; t)
{
...
}
</code></pre>
<p>Der Intel C++ Compiler gibt folgendes aus:<br />
error: no instance of function template &quot;foo&quot; matches the argument list<br />
argument types are: (A&lt;int&gt;::SubType)<br />
foo(t);<br />
^</p>
<p>G++ liefert folgendes:<br />
error: no matching function for call to ‘foo(A&lt;int&gt;::SubType&amp;)’</p>
<p>Wenn ich &quot;typename&quot; in der Funktionssignatur weglasse, dann meint der Intel C++ Compiler, dass foo weder eine Funktion noch ein statisches Member sei.</p>
<p>Was ist das Problem?</p>
<p>Grüße,<br />
Kevin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2103496</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2103496</guid><dc:creator><![CDATA[XtrmK3v0r]]></dc:creator><pubDate>Mon, 08 Aug 2011 15:11:37 GMT</pubDate></item><item><title><![CDATA[Reply to Verschachtelte Klassen in Templateklassen on Mon, 08 Aug 2011 16:16:19 GMT]]></title><description><![CDATA[<p>XtrmK3v0r schrieb:</p>
<blockquote>
<p>Was ist das Problem?</p>
</blockquote>
<p>A&lt;U&gt;::SubType ist kein Kontext, in dem U deduziert werden kann. Du müsstest U explizit mit angeben, also</p>
<pre><code class="language-cpp">foo&lt;int&gt;(t);
</code></pre>
<p>Kleines (sinnfreies) Beispiel, um den Grund zu illustrieren:</p>
<pre><code class="language-cpp">template &lt;typename T&gt; struct Foo {
    typedef int type;
};
template &lt;typename T&gt; void foo(typename Foo&lt;T&gt;::type);

template &lt;typename T&gt; struct Bar {
    typedef T type;
};
template &lt;&gt; struct Bar&lt;void&gt; {
    typedef int type;
};
template &lt;typename T&gt; void bar(typename Bar&lt;T&gt;::type);

int main()
{
     int x;
     foo(x); // T könnte alles mögliche sein
     bar(x); // könnte int oder void sein
}
</code></pre>
<p>Um überhaupt herauszubekommen, ob ein bestimmtes Templateargument passt, müsst der Compiler alle Argumente ausprobieren und das zugehörige Template instantiieren. Das geht nat. nicht. Übrigens ist auch schon die Tatsache, dass typenmae benutzt werden muss, ein starker Hinweis darauf, dass der Kontext nicht deduzierbar ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2103519</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2103519</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 08 Aug 2011 16:16:19 GMT</pubDate></item><item><title><![CDATA[Reply to Verschachtelte Klassen in Templateklassen on Mon, 08 Aug 2011 16:14:00 GMT]]></title><description><![CDATA[<p>Ah okay vielen Dank! Das macht natürlich Sinn. Der Compiler kann ja gar nicht wissen welche exakte Klasse zu instanziieren ist. Du meintest sicherlich in den Zeilen 6 und 9 'Bar' anstatt 'Foo' oder?!</p>
<p>Grüße,<br />
Kevin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2103539</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2103539</guid><dc:creator><![CDATA[XtrmK3v0r]]></dc:creator><pubDate>Mon, 08 Aug 2011 16:14:00 GMT</pubDate></item><item><title><![CDATA[Reply to Verschachtelte Klassen in Templateklassen on Mon, 08 Aug 2011 16:15:59 GMT]]></title><description><![CDATA[<p>XtrmK3v0r schrieb:</p>
<blockquote>
<p>Du meintest sicherlich in den Zeilen 6 und 9 'Bar' anstatt 'Foo' oder?!</p>
</blockquote>
<p>ja.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2103541</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2103541</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 08 Aug 2011 16:15:59 GMT</pubDate></item></channel></rss>