<?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[Objekt aus Klassen-Template heraus liefern lassen]]></title><description><![CDATA[<p>Guten Abend zusammen,<br />
folgender Code erzeugt einen Compilerfehler, den ich leider nicht verstehe:</p>
<pre><code class="language-cpp">template&lt;class T&gt;
class A
{
    class B
    {

    };

 public:
    B getB();
    int getInt();
};

template &lt;class T&gt; B A&lt;T&gt;::getB()
{
}

template &lt;class T&gt; int A&lt;T&gt;::getInt()
{
}
</code></pre>
<p>Mein Problem ist, warum der Compiler bei der Funktion getB() nun meckert, getInt funktioniert ja schließlich auch. Wie komme ich also an das B-Objekt ran. Die Struktur soll so erhalten bleiben, sprich, ich möchte die Implementierung nicht in die Klassendeklaration mit reinnehmen.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/145848/objekt-aus-klassen-template-heraus-liefern-lassen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 03 Sep 2026 10:23:28 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/145848.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 01 May 2006 19:38:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Objekt aus Klassen-Template heraus liefern lassen on Mon, 01 May 2006 19:38:16 GMT]]></title><description><![CDATA[<p>Guten Abend zusammen,<br />
folgender Code erzeugt einen Compilerfehler, den ich leider nicht verstehe:</p>
<pre><code class="language-cpp">template&lt;class T&gt;
class A
{
    class B
    {

    };

 public:
    B getB();
    int getInt();
};

template &lt;class T&gt; B A&lt;T&gt;::getB()
{
}

template &lt;class T&gt; int A&lt;T&gt;::getInt()
{
}
</code></pre>
<p>Mein Problem ist, warum der Compiler bei der Funktion getB() nun meckert, getInt funktioniert ja schließlich auch. Wie komme ich also an das B-Objekt ran. Die Struktur soll so erhalten bleiben, sprich, ich möchte die Implementierung nicht in die Klassendeklaration mit reinnehmen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1049222</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1049222</guid><dc:creator><![CDATA[desto]]></dc:creator><pubDate>Mon, 01 May 2006 19:38:16 GMT</pubDate></item><item><title><![CDATA[Reply to Objekt aus Klassen-Template heraus liefern lassen on Mon, 01 May 2006 19:51:57 GMT]]></title><description><![CDATA[<p>vielleicht</p>
<pre><code class="language-cpp">template &lt;class T&gt; A&lt;T&gt;::B A&lt;T&gt;::getB()
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1049230</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1049230</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 01 May 2006 19:51:57 GMT</pubDate></item><item><title><![CDATA[Reply to Objekt aus Klassen-Template heraus liefern lassen on Mon, 01 May 2006 19:58:29 GMT]]></title><description><![CDATA[<p>Danke für Deine Mühe aber das ist es leider nicht.</p>
<p>Die Meldung, die mir der gcc dabei ausspuckt lautet:<br />
*expected constructor, destructor, or type conversion before »A«<br />
*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1049234</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1049234</guid><dc:creator><![CDATA[desto]]></dc:creator><pubDate>Mon, 01 May 2006 19:58:29 GMT</pubDate></item><item><title><![CDATA[Reply to Objekt aus Klassen-Template heraus liefern lassen on Mon, 01 May 2006 20:04:02 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">template &lt;class T&gt; typename A&lt;T&gt;::B A&lt;T&gt;::getB()
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1049238</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1049238</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Mon, 01 May 2006 20:04:02 GMT</pubDate></item><item><title><![CDATA[Reply to Objekt aus Klassen-Template heraus liefern lassen on Mon, 01 May 2006 20:14:57 GMT]]></title><description><![CDATA[<p>Besten Dank, das funktioniert.</p>
<p>Zur Begründung:<br />
Heißt das, ich muss das Schlüsselwort typename genau deswegen verwenden, um den Typen, den das Template irgendwann mal haben soll, genau anzusprechen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1049241</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1049241</guid><dc:creator><![CDATA[desto]]></dc:creator><pubDate>Mon, 01 May 2006 20:14:57 GMT</pubDate></item><item><title><![CDATA[Reply to Objekt aus Klassen-Template heraus liefern lassen on Mon, 01 May 2006 20:20:11 GMT]]></title><description><![CDATA[<p>Wenn du auf ein Element einer Template-Klasse zugreifst nimmt der Compiler immer ein Objekt an, wenn es sich dabei aber um nen Typ handelt, dann musst du ihm das explizit mit typename sagen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1049247</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1049247</guid><dc:creator><![CDATA[Dr. Prof]]></dc:creator><pubDate>Mon, 01 May 2006 20:20:11 GMT</pubDate></item></channel></rss>