<?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-Klassen-Problem]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich versuche gerade einmal eine Template-Klasse zu entwerfen und habe es dann auch endlich geschafft, nur gibt<br />
es bei der weiteren Implementierung ein Problem mit dem Linker und ich weiß nicht woran das liegt. Ich hoffe<br />
ihr könnt mir da weiter helfen!</p>
<p>Zuerst einmal kommt hier der das Problem betreffene Teil der Template-Klasse. Diese Klasse ist übrigens fertig implementiert und alles wird korrekt kompiliert, etc. Die Klasse CVector wird dabei vorausgesetzt, die ist hier nicht von Interesse!</p>
<pre><code>template &lt;class TYPE&gt; class CCellularAutomata
{
public:
	TYPE	getCellState( CVector vecCellPos );
	virtual TYPE translateCell( CVector vecCellPos ) = 0;
}

template&lt;class TYPE&gt; TYPE CCellularAutomata&lt;TYPE&gt;::getCellState( CVector vecCellPos )
{
	uint32	intOffset = 0;
	uint32	intFactor = 1;

	for (uint32 intCounter=0; intCounter&lt;vecCellPos.getDimension(); intCounter++)
	{
		intOffset += (vecCellPos.getItem(intCounter) % intSize) * intSize;
		intFactor *= intSize;
	}

	if (intOffset &lt; intCellCount)	return fooCell[intOffset];
	return NULL;
}
</code></pre>
<p>Jetzt habe ich hier noch die Implemtierung der abstrakten Funktion translateCell in einer Subklasse!</p>
<pre><code>class CShrinkAutomata : public CCellularAutomata&lt;strucCell&gt;
{
public:	
	strucCell translateCell(  CVector vecCellPos );
};
</code></pre>
<p>Hierbei ist strucCell eine einfache Struktur, die z.B. folgendermaßen definiert sein könnte:</p>
<pre><code>struct strucCell
{
	int	intColor;
	double	dblIrgendwas;
};
</code></pre>
<p>Soweit so gut, versuche ich jetzt aber die Funktion aus CShrinkAutomata zu implementieren, so gibt es ein Problem!</p>
<pre><code>strucCell	CShrinkAutomata::translateCell( CVector vecCellPos )
{
	/* strucCell	oldCell = getCellState( vecCellPos ); */
	strucCell	newCell;
	return 		newCell;
}
</code></pre>
<p>Bis jetzt kompiliert und linkt der Compiler alles, aber wenn ich hier die auskommentierte Zeile hereinnehme, dann bricht der Compiler mit folgender Fehlermeldung ab:<br />
shrink.obj : error LNK2001: Nichtaufgeloestes externes Symbol &quot;public: struct strucCell __thiscall CCellularAutomata&lt;struct strucCell&gt;::getCellState(class CVector)&quot; (?getCellState@?$CCellularAutomata@UstrucCell@@@@QAE?AUstrucCell@@VCVector@@@Z)<br />
Debug/QueenBee.exe : fatal error LNK1120: 1 unaufgeloeste externe Verweise</p>
<p>Habe ich irgendwas falsch gemacht oder etwas übersehen?</p>
<p>Pomplito</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/135091/template-klassen-problem</link><generator>RSS for Node</generator><lastBuildDate>Fri, 28 Aug 2026 22:11:32 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/135091.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 30 Jan 2006 16:59:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Template-Klassen-Problem on Mon, 30 Jan 2006 16:59:38 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich versuche gerade einmal eine Template-Klasse zu entwerfen und habe es dann auch endlich geschafft, nur gibt<br />
es bei der weiteren Implementierung ein Problem mit dem Linker und ich weiß nicht woran das liegt. Ich hoffe<br />
ihr könnt mir da weiter helfen!</p>
<p>Zuerst einmal kommt hier der das Problem betreffene Teil der Template-Klasse. Diese Klasse ist übrigens fertig implementiert und alles wird korrekt kompiliert, etc. Die Klasse CVector wird dabei vorausgesetzt, die ist hier nicht von Interesse!</p>
<pre><code>template &lt;class TYPE&gt; class CCellularAutomata
{
public:
	TYPE	getCellState( CVector vecCellPos );
	virtual TYPE translateCell( CVector vecCellPos ) = 0;
}

template&lt;class TYPE&gt; TYPE CCellularAutomata&lt;TYPE&gt;::getCellState( CVector vecCellPos )
{
	uint32	intOffset = 0;
	uint32	intFactor = 1;

	for (uint32 intCounter=0; intCounter&lt;vecCellPos.getDimension(); intCounter++)
	{
		intOffset += (vecCellPos.getItem(intCounter) % intSize) * intSize;
		intFactor *= intSize;
	}

	if (intOffset &lt; intCellCount)	return fooCell[intOffset];
	return NULL;
}
</code></pre>
<p>Jetzt habe ich hier noch die Implemtierung der abstrakten Funktion translateCell in einer Subklasse!</p>
<pre><code>class CShrinkAutomata : public CCellularAutomata&lt;strucCell&gt;
{
public:	
	strucCell translateCell(  CVector vecCellPos );
};
</code></pre>
<p>Hierbei ist strucCell eine einfache Struktur, die z.B. folgendermaßen definiert sein könnte:</p>
<pre><code>struct strucCell
{
	int	intColor;
	double	dblIrgendwas;
};
</code></pre>
<p>Soweit so gut, versuche ich jetzt aber die Funktion aus CShrinkAutomata zu implementieren, so gibt es ein Problem!</p>
<pre><code>strucCell	CShrinkAutomata::translateCell( CVector vecCellPos )
{
	/* strucCell	oldCell = getCellState( vecCellPos ); */
	strucCell	newCell;
	return 		newCell;
}
</code></pre>
<p>Bis jetzt kompiliert und linkt der Compiler alles, aber wenn ich hier die auskommentierte Zeile hereinnehme, dann bricht der Compiler mit folgender Fehlermeldung ab:<br />
shrink.obj : error LNK2001: Nichtaufgeloestes externes Symbol &quot;public: struct strucCell __thiscall CCellularAutomata&lt;struct strucCell&gt;::getCellState(class CVector)&quot; (?getCellState@?$CCellularAutomata@UstrucCell@@@@QAE?AUstrucCell@@VCVector@@@Z)<br />
Debug/QueenBee.exe : fatal error LNK1120: 1 unaufgeloeste externe Verweise</p>
<p>Habe ich irgendwas falsch gemacht oder etwas übersehen?</p>
<p>Pomplito</p>
]]></description><link>https://www.c-plusplus.net/forum/post/981286</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/981286</guid><dc:creator><![CDATA[Pomplito]]></dc:creator><pubDate>Mon, 30 Jan 2006 16:59:38 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Klassen-Problem on Mon, 30 Jan 2006 17:22:34 GMT]]></title><description><![CDATA[<p>Hi,</p>
<pre><code class="language-cpp">if (intOffset &lt; intCellCount)    return fooCell[intOffset];
</code></pre>
<p>was ist fooCell[]? Sollte es hier nicht etwas vom Typ &lt;TYPE&gt; zurück gegeben werden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/981331</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/981331</guid><dc:creator><![CDATA[Cyriz]]></dc:creator><pubDate>Mon, 30 Jan 2006 17:22:34 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Klassen-Problem on Mon, 30 Jan 2006 17:32:01 GMT]]></title><description><![CDATA[<p>Hi, das ist aber von selben Typ, das hatte ich nur vergessen anzugeben, also so:</p>
<pre><code>template &lt;class TYPE&gt; class CCellularAutomata
{
public:
	TYPE	getCellState( CVector vecCellPos );
	virtual TYPE translateCell( CVector vecCellPos ) = 0;

private:
	TYPE	*fooCell;
};
</code></pre>
<p>Dieses Feld wird dann dynamisch erstellt, etc. (intCellCount ist übrigens ein Integer)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/981358</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/981358</guid><dc:creator><![CDATA[Pomplito]]></dc:creator><pubDate>Mon, 30 Jan 2006 17:32:01 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Klassen-Problem on Mon, 30 Jan 2006 17:43:10 GMT]]></title><description><![CDATA[<p>Nur zur Sicherheit: Hast du die Definition von CCellularAutomata::getCellState() auch mit im Header stehen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/981381</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/981381</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 30 Jan 2006 17:43:10 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Klassen-Problem on Mon, 30 Jan 2006 18:13:22 GMT]]></title><description><![CDATA[<p>Ja natürlich, ich habe immer mein .h File mit den Definitionen und das .cpp File mit der Implementation... <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=":/"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/981430</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/981430</guid><dc:creator><![CDATA[Pomplito]]></dc:creator><pubDate>Mon, 30 Jan 2006 18:13:22 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Klassen-Problem on Mon, 30 Jan 2006 18:33:16 GMT]]></title><description><![CDATA[<p>Du meinst Du hast die Deklaration im Header und die Definition (=Implementierung) in der .cpp-Datei? <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>
<p>Genau dort liegt der Fehler: Dem Compiler muss zur Instanzierung eines Templates die komplette Templatedefinition vorliegen, weshalb man die nicht in eine andere .cpp-Datei auslagern darf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/981441</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/981441</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Mon, 30 Jan 2006 18:33:16 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Klassen-Problem on Mon, 30 Jan 2006 19:28:33 GMT]]></title><description><![CDATA[<p>Nunja, man darf es schon. Problem ist nur, dass dafür <em>export</em> unterstützt werden müsste. Und das macht momentan so gut wie kein Compiler.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/981473</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/981473</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Mon, 30 Jan 2006 19:28:33 GMT</pubDate></item></channel></rss>