<?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[Probleme mit Templates?]]></title><description><![CDATA[<p>Hallo Leute, habe folgende Klasse definiert:</p>
<pre><code>#ifndef LIST_HPP
#define LIST_HPP

#include &quot;list_item.hpp&quot;

template&lt;class typ&gt;
class list
{
    public:
        explicit list()
            {}

        void hello();
};

#endif
</code></pre>
<p>...und hier implementiert (eine Memberfunktion):</p>
<pre><code>#include &quot;list.hpp&quot;
#include &lt;iostream&gt;
using namespace std;

template&lt;class typ&gt;
void list&lt;typ&gt;::hello()
{
    cout &lt;&lt; &quot;hello&quot; &lt;&lt; endl;
}
</code></pre>
<p>in main dann ein Klassenobjekt definiert:</p>
<pre><code>int main)
{
    list&lt;int&gt; liste;
    liste.hello();
    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
<p>und prompt motzt der Linker:<br />
[Linker error] undefined reference to `list&lt;int&gt;::hello()'</p>
<p>Das passiert auch nur, wenn ich die Klasse als Template definiere, warum, was muss ich tun um das Problem zu lösen?</p>
<p>benutze devC++ mit Mingw Compiler</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/173743/probleme-mit-templates</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 09:32:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/173743.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 19 Feb 2007 13:49:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Probleme mit Templates? on Mon, 19 Feb 2007 13:49:02 GMT]]></title><description><![CDATA[<p>Hallo Leute, habe folgende Klasse definiert:</p>
<pre><code>#ifndef LIST_HPP
#define LIST_HPP

#include &quot;list_item.hpp&quot;

template&lt;class typ&gt;
class list
{
    public:
        explicit list()
            {}

        void hello();
};

#endif
</code></pre>
<p>...und hier implementiert (eine Memberfunktion):</p>
<pre><code>#include &quot;list.hpp&quot;
#include &lt;iostream&gt;
using namespace std;

template&lt;class typ&gt;
void list&lt;typ&gt;::hello()
{
    cout &lt;&lt; &quot;hello&quot; &lt;&lt; endl;
}
</code></pre>
<p>in main dann ein Klassenobjekt definiert:</p>
<pre><code>int main)
{
    list&lt;int&gt; liste;
    liste.hello();
    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
}
</code></pre>
<p>und prompt motzt der Linker:<br />
[Linker error] undefined reference to `list&lt;int&gt;::hello()'</p>
<p>Das passiert auch nur, wenn ich die Klasse als Template definiere, warum, was muss ich tun um das Problem zu lösen?</p>
<p>benutze devC++ mit Mingw Compiler</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1231211</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231211</guid><dc:creator><![CDATA[benschni]]></dc:creator><pubDate>Mon, 19 Feb 2007 13:49:02 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Templates? on Mon, 19 Feb 2007 13:52:34 GMT]]></title><description><![CDATA[<p>Template-Funktionen und Methoden mußt du (inline) im Header definieren, sonst macht der Compiler/Linker nicht mit (in der list.cpp weiß er nicht, für welchen Typ er die Funktion erstellen soll, in der main.cpp kennt er ihre Definition nicht - ergo kann er keinen Maschinencode erzeugen).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1231213</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231213</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 19 Feb 2007 13:52:34 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Templates? on Mon, 19 Feb 2007 13:56:11 GMT]]></title><description><![CDATA[<p>Danke für die schnelle Antwort!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1231215</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231215</guid><dc:creator><![CDATA[benschni]]></dc:creator><pubDate>Mon, 19 Feb 2007 13:56:11 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Templates? on Mon, 19 Feb 2007 13:56:32 GMT]]></title><description><![CDATA[<p>Naja, inline muss es nicht sein. Wenn du Wert darauf legst, das Implementierung und Schnittstelle &quot;getrennt&quot; sind, kannst du auch die entsprechende .cpp am Ende des Headers inkludieren (dann ist es allerdings ratsam, deren Endung zB in .ipp zu ändern).</p>
<p>Übrigens ist das Problem auch in den &quot;Meistgestellten Fragen&quot;, Frage 5 erläutert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1231216</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231216</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Mon, 19 Feb 2007 13:56:32 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Templates? on Mon, 19 Feb 2007 14:11:12 GMT]]></title><description><![CDATA[<p>Danke, hätte nie gedacht, dass das nur auf diese Weise funktioniert, aber man wird immer wieder eines Besseren belehrt! <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/1231238</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231238</guid><dc:creator><![CDATA[benschni]]></dc:creator><pubDate>Mon, 19 Feb 2007 14:11:12 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Templates? on Mon, 19 Feb 2007 14:28:12 GMT]]></title><description><![CDATA[<p>Sorry, muss euch nochmal stören</p>
<p>hab deinen Tipp befolgt .filmor:</p>
<p>.filmor schrieb:</p>
<blockquote>
<p>Naja, inline muss es nicht sein. Wenn du Wert darauf legst, das Implementierung und Schnittstelle &quot;getrennt&quot; sind, kannst du auch die entsprechende .cpp am Ende des Headers inkludieren (dann ist es allerdings ratsam, deren Endung zB in .ipp zu ändern).</p>
</blockquote>
<pre><code>#ifndef LIST_HPP
#define LIST_HPP

#include &quot;list_item.hpp&quot;

template&lt;class typ&gt;
class list
{
    public:
        explicit list()
            {}

        void hello();
};

#include &quot;list.ipp&quot;

#endif
</code></pre>
<p>Funktioniert aber nicht und ich hab auch keine Ahnung was für eine Art von Fehler das ist (Compiler/Linker?):<br />
C:\Sicherungsdateien\Stufe1\Programmieren\C++\Klassen\Liste(3)\Makefile.win [Build Error] [Liste.exe] Error 1</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1231252</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231252</guid><dc:creator><![CDATA[benschni]]></dc:creator><pubDate>Mon, 19 Feb 2007 14:28:12 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Templates? on Mon, 19 Feb 2007 14:38:17 GMT]]></title><description><![CDATA[<p>Man könnte auch das Schlüsselwort export verwenden. Dass wäre zwar statndard konform. Allerdings kenne ich nur einen Compiler der das implementiert.(Comeau)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1231262</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231262</guid><dc:creator><![CDATA[templäd]]></dc:creator><pubDate>Mon, 19 Feb 2007 14:38:17 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Templates? on Mon, 19 Feb 2007 14:41:39 GMT]]></title><description><![CDATA[<p>Jupp, danke, dieser Tipp steht auch schon bei den meistgestellten Fragen, hab eben mal nachgeschaut, aber hier hab ich inzwischen ein anderes Problem, woher kommt dieser Build Error?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1231267</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231267</guid><dc:creator><![CDATA[benschni]]></dc:creator><pubDate>Mon, 19 Feb 2007 14:41:39 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Templates? on Mon, 19 Feb 2007 14:50:51 GMT]]></title><description><![CDATA[<p>Also bei mir klappts. Kontrollier nochmal deine Build-Einstellungen, die ipp-Datei soll /nicht/ kompiliert werden.<br />
Außerdem musst du jetzt darauf achten, dass list.ipp ein Header ist, using namespace ist also nicht!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1231278</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231278</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Mon, 19 Feb 2007 14:50:51 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Templates? on Mon, 19 Feb 2007 15:01:14 GMT]]></title><description><![CDATA[<p>Danke!! Es klappt, auch wenn ich nicht weiß, was du damit meinst</p>
<p>.filmor schrieb:</p>
<blockquote>
<p>Außerdem musst du jetzt darauf achten, dass list.ipp ein Header ist, using namespace ist also nicht!</p>
</blockquote>
<p>kann using namespace std; verwenden</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1231286</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231286</guid><dc:creator><![CDATA[benschni]]></dc:creator><pubDate>Mon, 19 Feb 2007 15:01:14 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Templates? on Mon, 19 Feb 2007 15:14:03 GMT]]></title><description><![CDATA[<p>ach ich habs schon gefunden, das Stichwort ist namespace-pollution</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1231298</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1231298</guid><dc:creator><![CDATA[benschni]]></dc:creator><pubDate>Mon, 19 Feb 2007 15:14:03 GMT</pubDate></item></channel></rss>