<?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[Template Funktion in Template Klasse schreiben]]></title><description><![CDATA[<p>Wenn ich eine Template Funktion in einer Template Klasse selber ausprogrammiere, dann klappt das wunderbar:</p>
<pre><code class="language-cpp">template &lt;class Type&gt;
class Foo
{
public:
        Type item;
        template &lt;class otherType&gt;
        void bar(otherType b)
        {
                this-&gt;item = b;
        }
};
</code></pre>
<p>Möchte ich sie aber ausserhalb der Klasse ausprogrammieren, dann wirft mir der g++ Fehler entgegen:</p>
<pre><code class="language-cpp">template &lt;class Type&gt;
class Foo
{
public:
        Type item;
        template &lt;class otherType&gt;
        void bar(otherType b);
};

template &lt;class Type, class  otherType&gt;
void Foo&lt;Type&gt;::bar(otherType b)
{
        this-&gt;item = b;
}
</code></pre>
<p>Die Fehlermeldung ist folgende:</p>
<pre><code>tst.cpp:11: error: prototype for ‘void Foo&lt;Type&gt;::bar(otherType)’ does not match any in class ‘Foo&lt;Type&gt;’
tst.cpp:7: error: candidate is: template&lt;class Type&gt; template&lt;class otherType&gt; void Foo::bar(otherType)
</code></pre>
<p>Leider kann ich an der Fehlermeldung nichts ablesen, was ich hier falsch geschrieben habe.</p>
<p>Kann mich da jemand aufklären?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/251032/template-funktion-in-template-klasse-schreiben</link><generator>RSS for Node</generator><lastBuildDate>Tue, 15 Sep 2026 18:52:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/251032.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 28 Sep 2009 12:10:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Template Funktion in Template Klasse schreiben on Mon, 28 Sep 2009 12:10:54 GMT]]></title><description><![CDATA[<p>Wenn ich eine Template Funktion in einer Template Klasse selber ausprogrammiere, dann klappt das wunderbar:</p>
<pre><code class="language-cpp">template &lt;class Type&gt;
class Foo
{
public:
        Type item;
        template &lt;class otherType&gt;
        void bar(otherType b)
        {
                this-&gt;item = b;
        }
};
</code></pre>
<p>Möchte ich sie aber ausserhalb der Klasse ausprogrammieren, dann wirft mir der g++ Fehler entgegen:</p>
<pre><code class="language-cpp">template &lt;class Type&gt;
class Foo
{
public:
        Type item;
        template &lt;class otherType&gt;
        void bar(otherType b);
};

template &lt;class Type, class  otherType&gt;
void Foo&lt;Type&gt;::bar(otherType b)
{
        this-&gt;item = b;
}
</code></pre>
<p>Die Fehlermeldung ist folgende:</p>
<pre><code>tst.cpp:11: error: prototype for ‘void Foo&lt;Type&gt;::bar(otherType)’ does not match any in class ‘Foo&lt;Type&gt;’
tst.cpp:7: error: candidate is: template&lt;class Type&gt; template&lt;class otherType&gt; void Foo::bar(otherType)
</code></pre>
<p>Leider kann ich an der Fehlermeldung nichts ablesen, was ich hier falsch geschrieben habe.</p>
<p>Kann mich da jemand aufklären?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1785353</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1785353</guid><dc:creator><![CDATA[knuddelvieh]]></dc:creator><pubDate>Mon, 28 Sep 2009 12:10:54 GMT</pubDate></item><item><title><![CDATA[Reply to Template Funktion in Template Klasse schreiben on Mon, 28 Sep 2009 12:23:30 GMT]]></title><description><![CDATA[<p>So geht das:</p>
<pre><code class="language-cpp">template &lt;class Type&gt;
class Foo
{
public:
        Type item;
        template &lt;class otherType&gt;
        void bar(otherType b);
};

template &lt;class Type&gt;
template &lt;class otherType&gt; void Foo&lt;Type&gt;::bar(otherType b)
{
        this-&gt;item = b;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1785365</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1785365</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 28 Sep 2009 12:23:30 GMT</pubDate></item><item><title><![CDATA[Reply to Template Funktion in Template Klasse schreiben on Mon, 28 Sep 2009 12:43:58 GMT]]></title><description><![CDATA[<p>Ahh, vielen Dank. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1785384</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1785384</guid><dc:creator><![CDATA[knuddelvieh]]></dc:creator><pubDate>Mon, 28 Sep 2009 12:43:58 GMT</pubDate></item></channel></rss>