<?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&amp;lt;class T&amp;gt; List {...}; Problem]]></title><description><![CDATA[<p>Guten Tag zusammen,</p>
<p>es wäre super, wenn mir jemand helfen könnte.</p>
<p>Zu Übungszwecken möchte ich eine vector Klasse schreiben und nenne sie &quot;List&quot;.<br />
List.h :</p>
<pre><code class="language-cpp">#pragma once

template &lt;class T&gt; class List
{
private:
	T* list;
	unsigned int count;
public:
	List(void);
	void add(T element);
	T&amp; operator[] (const int nIndex);
	~List(void);
};
</code></pre>
<p>List.cpp :</p>
<pre><code class="language-cpp">#include &quot;List.h&quot;
#include &lt;cstdlib&gt;

#ifndef NULL
#define NULL 0
#endif

template &lt;class T&gt; List&lt;T&gt;::List(void)
{
	this-&gt;list = NULL;
	this-&gt;count = NULL;
}

template &lt;class T&gt; void List&lt;T&gt;::add(T element)
{
	this-&gt;count++; // increment field size
	this-&gt;list = (T*) realloc(this-&gt;list, this-&gt;count * sizeof(T)); // realloc dynamic storage
	this-&gt;list[this-&gt;count-1] = element; // adding last entry
}

// overloading [] operator
template &lt;class T&gt; T&amp; List&lt;T&gt;::operator[] (const int nIndex)
{
	return this-&gt;list[nIndex];
}
template &lt;class T&gt; List&lt;T&gt;::~List(void)
{
	free (this-&gt;list);
}
</code></pre>
<p>Ich benutze MVS 2005 und wennich das ganze Projekt erstelle dann kommen keine Fehler, wenn ich jedoch versuche es zu debuggen, dann erhalte ich folgende Meldung:</p>
<blockquote>
<p>1&gt;------ Erstellen gestartet: Projekt: List, Konfiguration: Debug Win32 ------<br />
1&gt;Kompilieren...<br />
1&gt;Main.cpp<br />
1&gt;Verknüpfen...<br />
1&gt;Main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol &quot;&quot;public: __thiscall List&lt;int&gt;::~List&lt;int&gt;(void)&quot; (??1?List@H@@QAE@XZ)" in Funktion "\_main".  
1>Main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: \_\_thiscall List<int>::List<int>(void)" (??0?List@H@@QAE@XZ)&quot; in Funktion &quot;_main&quot;.<br />
1&gt;H:\EigeneDaten\Visual Studio 2005\Projects\C++\List\Debug\List.exe : fatal error LNK1120: 2 nicht aufgelöste externe Verweise.<br />
1&gt;Das Buildprotokoll wurde unter &quot;file://h:\EigeneDaten\Visual Studio 2005\Projects\C++\List\Debug\BuildLog.htm&quot; gespeichert.<br />
1&gt;List - 3 Fehler, 0 Warnung(en)<br />
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========</p>
</blockquote>
<p>Meine Main ist lediglich:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include &quot;List.h&quot;

using namespace std;

int main (void)
{
	List&lt;int&gt; d;
	return 0;
}
</code></pre>
<p>Vielen Dank für eure Hilfe, ich weiß echt nicht woran das liegt! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/244435/template-lt-class-t-gt-list-problem</link><generator>RSS for Node</generator><lastBuildDate>Sat, 19 Sep 2026 10:42:17 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/244435.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 30 Jun 2009 09:12:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to template&amp;lt;class T&amp;gt; List {...}; Problem on Tue, 30 Jun 2009 09:12:27 GMT]]></title><description><![CDATA[<p>Guten Tag zusammen,</p>
<p>es wäre super, wenn mir jemand helfen könnte.</p>
<p>Zu Übungszwecken möchte ich eine vector Klasse schreiben und nenne sie &quot;List&quot;.<br />
List.h :</p>
<pre><code class="language-cpp">#pragma once

template &lt;class T&gt; class List
{
private:
	T* list;
	unsigned int count;
public:
	List(void);
	void add(T element);
	T&amp; operator[] (const int nIndex);
	~List(void);
};
</code></pre>
<p>List.cpp :</p>
<pre><code class="language-cpp">#include &quot;List.h&quot;
#include &lt;cstdlib&gt;

#ifndef NULL
#define NULL 0
#endif

template &lt;class T&gt; List&lt;T&gt;::List(void)
{
	this-&gt;list = NULL;
	this-&gt;count = NULL;
}

template &lt;class T&gt; void List&lt;T&gt;::add(T element)
{
	this-&gt;count++; // increment field size
	this-&gt;list = (T*) realloc(this-&gt;list, this-&gt;count * sizeof(T)); // realloc dynamic storage
	this-&gt;list[this-&gt;count-1] = element; // adding last entry
}

// overloading [] operator
template &lt;class T&gt; T&amp; List&lt;T&gt;::operator[] (const int nIndex)
{
	return this-&gt;list[nIndex];
}
template &lt;class T&gt; List&lt;T&gt;::~List(void)
{
	free (this-&gt;list);
}
</code></pre>
<p>Ich benutze MVS 2005 und wennich das ganze Projekt erstelle dann kommen keine Fehler, wenn ich jedoch versuche es zu debuggen, dann erhalte ich folgende Meldung:</p>
<blockquote>
<p>1&gt;------ Erstellen gestartet: Projekt: List, Konfiguration: Debug Win32 ------<br />
1&gt;Kompilieren...<br />
1&gt;Main.cpp<br />
1&gt;Verknüpfen...<br />
1&gt;Main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol &quot;&quot;public: __thiscall List&lt;int&gt;::~List&lt;int&gt;(void)&quot; (??1?List@H@@QAE@XZ)" in Funktion "\_main".  
1>Main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: \_\_thiscall List<int>::List<int>(void)" (??0?List@H@@QAE@XZ)&quot; in Funktion &quot;_main&quot;.<br />
1&gt;H:\EigeneDaten\Visual Studio 2005\Projects\C++\List\Debug\List.exe : fatal error LNK1120: 2 nicht aufgelöste externe Verweise.<br />
1&gt;Das Buildprotokoll wurde unter &quot;file://h:\EigeneDaten\Visual Studio 2005\Projects\C++\List\Debug\BuildLog.htm&quot; gespeichert.<br />
1&gt;List - 3 Fehler, 0 Warnung(en)<br />
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========</p>
</blockquote>
<p>Meine Main ist lediglich:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include &quot;List.h&quot;

using namespace std;

int main (void)
{
	List&lt;int&gt; d;
	return 0;
}
</code></pre>
<p>Vielen Dank für eure Hilfe, ich weiß echt nicht woran das liegt! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1734938</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1734938</guid><dc:creator><![CDATA[kronos_m]]></dc:creator><pubDate>Tue, 30 Jun 2009 09:12:27 GMT</pubDate></item><item><title><![CDATA[Reply to template&amp;lt;class T&amp;gt; List {...}; Problem on Tue, 30 Jun 2009 09:20:50 GMT]]></title><description><![CDATA[<p>kronos_m schrieb:</p>
<blockquote>
<p>...<br />
List.h :</p>
<pre><code class="language-cpp">...
</code></pre>
<p>List.cpp :</p>
<pre><code class="language-cpp">...
</code></pre>
</blockquote>
<p>Geht nicht mit templates.<br />
Die Implementierung mus mit in den Header!</p>
<p>Da gibt's sogar einen FAQ-Eintrag zu: <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39467.html" rel="nofollow">click</a>.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1734942</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1734942</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Tue, 30 Jun 2009 09:20:50 GMT</pubDate></item><item><title><![CDATA[Reply to template&amp;lt;class T&amp;gt; List {...}; Problem on Tue, 30 Jun 2009 12:57:18 GMT]]></title><description><![CDATA[<p>kronos_m schrieb:</p>
<blockquote>
<p>Zu Übungszwecken möchte ich eine vector Klasse schreiben und nenne sie &quot;List&quot;.</p>
</blockquote>
<p>Etwas verwirrend, wenn man bedenkt, dass &quot;List&quot; meistens verkettete Listen bezeichnet, findest du nicht? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735035</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735035</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 30 Jun 2009 12:57:18 GMT</pubDate></item><item><title><![CDATA[Reply to template&amp;lt;class T&amp;gt; List {...}; Problem on Tue, 30 Jun 2009 19:34:53 GMT]]></title><description><![CDATA[<p>Hab mir das einfach aus c# geklaugt, wo der vector in etwa der in c# verwendeten List&lt;typ&gt; entspricht!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735220</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735220</guid><dc:creator><![CDATA[Kronos_m]]></dc:creator><pubDate>Tue, 30 Jun 2009 19:34:53 GMT</pubDate></item><item><title><![CDATA[Reply to template&amp;lt;class T&amp;gt; List {...}; Problem on Tue, 30 Jun 2009 19:46:33 GMT]]></title><description><![CDATA[<p>Ich hab das ganze nun direkt in die List.h implementiert. Aber ein weiteres Problem:<br />
Die IntelliSense funktion scheint für meine template Klasse nicht mehr zu funktionieren. Woran liegt das und wie bekomme ich das hin, dass das doch geht? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<pre><code class="language-cpp">List&lt;int&gt; l;
	l.add(2);
	l.add(3);
	cout &lt;&lt; l.size() &lt;&lt; endl;
</code></pre>
<p>==&gt; funktioniert ohne Probleme!</p>
<p>Danke für eure Hilfe!</p>
<p>PS.: Benutze MVS 2005</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735229</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735229</guid><dc:creator><![CDATA[Kronos_m]]></dc:creator><pubDate>Tue, 30 Jun 2009 19:46:33 GMT</pubDate></item><item><title><![CDATA[Reply to template&amp;lt;class T&amp;gt; List {...}; Problem on Tue, 30 Jun 2009 20:29:33 GMT]]></title><description><![CDATA[<p>Kronos_m schrieb:</p>
<blockquote>
<p>Die IntelliSense funktion scheint für meine template Klasse nicht mehr zu funktionieren.</p>
</blockquote>
<p>Sollte eigtl nicht passieren - auch mal gespeichert und paar Sekunden gewartet?</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735259</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735259</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Tue, 30 Jun 2009 20:29:33 GMT</pubDate></item><item><title><![CDATA[Reply to template&amp;lt;class T&amp;gt; List {...}; Problem on Tue, 30 Jun 2009 20:39:34 GMT]]></title><description><![CDATA[<p>Habe einen anderen klugen Beitrag dazu gefunden.<br />
Habe die *.ncb Datei in dem Projektmappenverzeichnis gelöscht, seit dem läuft alles super <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Danke noch mal an alle...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735266</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735266</guid><dc:creator><![CDATA[Kronos_m]]></dc:creator><pubDate>Tue, 30 Jun 2009 20:39:34 GMT</pubDate></item><item><title><![CDATA[Reply to template&amp;lt;class T&amp;gt; List {...}; Problem on Tue, 30 Jun 2009 20:44:25 GMT]]></title><description><![CDATA[<p>kronos_m schrieb:</p>
<blockquote>
<p>[...] Zu Übungszwecken [...]</p>
<pre><code class="language-cpp">#pragma once

template &lt;class T&gt; class List
{
private:
	T* list;
	unsigned int count;
public:
	List(void);
	void add(T element);
	T&amp; operator[] (const int nIndex);
	~List(void);
};
</code></pre>
</blockquote>
<p>Ok, vier Sachen noch:</p>
<ul>
<li><code>#pragma once</code> ist kein C++ Standard</li>
<li>Deine Klasse verletzt die <a href="http://de.wikipedia.org/wiki/Dreierregel_(C%2B%2B)" rel="nofollow">Dreierregel</a> ==&gt; Du kannst das Ding nicht vernünftig kopieren oder zuweisen.</li>
<li>Man kann Dein Objekt gar nicht fragen, wieviele gültige Elemente es speichert.</li>
<li>Wenn ich eine Referenz des Typs const List&lt;T&gt;&amp; habe, kann ich damit nichts anfangen</li>
</ul>
<p>Für die letzten beiden Punkte siehe hier:</p>
<pre><code class="language-cpp">T      &amp; operator[]       (int idx);
    T const&amp; operator[] const (int idx);
    int size() const;
</code></pre>
<p>Gruß,<br />
SP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735268</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735268</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Tue, 30 Jun 2009 20:44:25 GMT</pubDate></item><item><title><![CDATA[Reply to template&amp;lt;class T&amp;gt; List {...}; Problem on Tue, 30 Jun 2009 20:48:41 GMT]]></title><description><![CDATA[<p>Sebastian Pizer schrieb:</p>
<blockquote>
<pre><code class="language-cpp">T      &amp; operator[]       (int idx);
    T const&amp; operator[] const (int idx);
    int size() const;
</code></pre>
</blockquote>
<p>Upps, wie peinlich... das zweite <code>const</code> kommt natürlich hinter <code>(int idx)</code> .</p>
<p>Gruß,<br />
SP</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735274</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735274</guid><dc:creator><![CDATA[Sebastian Pizer]]></dc:creator><pubDate>Tue, 30 Jun 2009 20:48:41 GMT</pubDate></item></channel></rss>