<?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 Spezialisierung -&amp;gt; Linker Problem]]></title><description><![CDATA[<p>Hallo,</p>
<p>Folgende Template Klasse funktioniert, solange ich den Header nur in einer Quellcode Datei benutze. Sobald ich den Header in einer weiteren Datei einbinde kommt dieser Linker Fehler:</p>
<blockquote>
<p>Test1.obj : error LNK2005: &quot;public: class fa::XY&lt;int&gt; &amp; __thiscall fa::XY&lt;int&gt;::operator=(class fa::XY&lt;double&gt; const &amp;)&quot; (??4?<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>X</mi><mi>Y</mi><mi mathvariant="normal">@</mi><mi>H</mi><mi mathvariant="normal">@</mi><mi>f</mi><mi>a</mi><mi mathvariant="normal">@</mi><mi mathvariant="normal">@</mi><mi>Q</mi><mi>A</mi><mi>E</mi><mi>A</mi><mi>A</mi><mi>V</mi><mn>0</mn><mn>1</mn><mi mathvariant="normal">@</mi><mi>A</mi><mi>B</mi><mi>V</mi><mo>?</mo></mrow><annotation encoding="application/x-tex">XY@H@fa@@QAEAAV01@ABV?</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.07847em;">X</span><span class="mord mathit" style="margin-right:0.22222em;">Y</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.08125em;">H</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.10764em;">f</span><span class="mord mathit">a</span><span class="mord mathrm">@</span><span class="mord mathrm">@</span><span class="mord mathit">Q</span><span class="mord mathit">A</span><span class="mord mathit" style="margin-right:0.05764em;">E</span><span class="mord mathit">A</span><span class="mord mathit">A</span><span class="mord mathit" style="margin-right:0.22222em;">V</span><span class="mord mathrm">0</span><span class="mord mathrm">1</span><span class="mord mathrm">@</span><span class="mord mathit">A</span><span class="mord mathit" style="margin-right:0.05017em;">B</span><span class="mord mathit" style="margin-right:0.22222em;">V</span><span class="mclose">?</span></span></span></span>XY@N@1@@Z) bereits in Main.obj definiert<br />
Debug/Konsole.exe : fatal error LNK1169: Ein oder mehrere mehrfach definierte Symbole gefunden</p>
</blockquote>
<p>Hier nun mein Template:</p>
<pre><code class="language-cpp">#ifndef FAXY_H
#define FAXY_H

namespace fa
{
	template &lt;class T&gt; class XY
	{
	public:
		XY();
		XY( T nx, T ny );
		XY( const XY&lt;T&gt; &amp;other );
		virtual ~XY();

		XY&lt;T&gt; &amp;operator=( const XY&lt;int&gt; &amp;right );
		XY&lt;T&gt; &amp;operator=( const XY&lt;double&gt; &amp;right );

		T x,y;
	};

	template &lt;class T&gt; XY&lt;T&gt;::XY() : x(0), y(0)
	{
	}

	template &lt;class T&gt; XY&lt;T&gt;::XY( T nx, T ny )
	{
		x = nx;
		y = ny;
	}

	template &lt;class T&gt; XY&lt;T&gt;::XY( const XY&lt;T&gt; &amp;other )
	{
		(*this) = other;
	}

	template &lt;class T&gt; XY&lt;T&gt;::~XY()
	{
	}

	template &lt;class T&gt; XY&lt;T&gt; &amp;XY&lt;T&gt;::operator=( const XY&lt;int&gt; &amp;right )
	{
		x = right.x;
		y = right.y;
		return (*this);
	}

	template &lt;class T&gt; XY&lt;T&gt; &amp;XY&lt;T&gt;::operator=( const XY&lt;double&gt; &amp;right )
	{
		x = right.x;
		y = right.y;
		return (*this);
	}
//Hier die Spezialisierung
	template &lt;&gt; XY&lt;int&gt; &amp;XY&lt;int&gt;::operator=( const XY&lt;double&gt; &amp;right )
	{
		x = Util::Round( right.x, 0 );
		y = Util::Round( right.y, 0 );
		return (*this);
	}
}

#endif
</code></pre>
<p>Ich weiß echt nicht woran das liegt. Danke für jede Hilfe</p>
<p>Cappo</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/88432/template-spezialisierung-gt-linker-problem</link><generator>RSS for Node</generator><lastBuildDate>Sun, 02 Aug 2026 21:01:09 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/88432.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 09 Oct 2004 17:35:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Template Spezialisierung -&amp;gt; Linker Problem on Sat, 09 Oct 2004 17:35:44 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Folgende Template Klasse funktioniert, solange ich den Header nur in einer Quellcode Datei benutze. Sobald ich den Header in einer weiteren Datei einbinde kommt dieser Linker Fehler:</p>
<blockquote>
<p>Test1.obj : error LNK2005: &quot;public: class fa::XY&lt;int&gt; &amp; __thiscall fa::XY&lt;int&gt;::operator=(class fa::XY&lt;double&gt; const &amp;)&quot; (??4?<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>X</mi><mi>Y</mi><mi mathvariant="normal">@</mi><mi>H</mi><mi mathvariant="normal">@</mi><mi>f</mi><mi>a</mi><mi mathvariant="normal">@</mi><mi mathvariant="normal">@</mi><mi>Q</mi><mi>A</mi><mi>E</mi><mi>A</mi><mi>A</mi><mi>V</mi><mn>0</mn><mn>1</mn><mi mathvariant="normal">@</mi><mi>A</mi><mi>B</mi><mi>V</mi><mo>?</mo></mrow><annotation encoding="application/x-tex">XY@H@fa@@QAEAAV01@ABV?</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.07847em;">X</span><span class="mord mathit" style="margin-right:0.22222em;">Y</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.08125em;">H</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.10764em;">f</span><span class="mord mathit">a</span><span class="mord mathrm">@</span><span class="mord mathrm">@</span><span class="mord mathit">Q</span><span class="mord mathit">A</span><span class="mord mathit" style="margin-right:0.05764em;">E</span><span class="mord mathit">A</span><span class="mord mathit">A</span><span class="mord mathit" style="margin-right:0.22222em;">V</span><span class="mord mathrm">0</span><span class="mord mathrm">1</span><span class="mord mathrm">@</span><span class="mord mathit">A</span><span class="mord mathit" style="margin-right:0.05017em;">B</span><span class="mord mathit" style="margin-right:0.22222em;">V</span><span class="mclose">?</span></span></span></span>XY@N@1@@Z) bereits in Main.obj definiert<br />
Debug/Konsole.exe : fatal error LNK1169: Ein oder mehrere mehrfach definierte Symbole gefunden</p>
</blockquote>
<p>Hier nun mein Template:</p>
<pre><code class="language-cpp">#ifndef FAXY_H
#define FAXY_H

namespace fa
{
	template &lt;class T&gt; class XY
	{
	public:
		XY();
		XY( T nx, T ny );
		XY( const XY&lt;T&gt; &amp;other );
		virtual ~XY();

		XY&lt;T&gt; &amp;operator=( const XY&lt;int&gt; &amp;right );
		XY&lt;T&gt; &amp;operator=( const XY&lt;double&gt; &amp;right );

		T x,y;
	};

	template &lt;class T&gt; XY&lt;T&gt;::XY() : x(0), y(0)
	{
	}

	template &lt;class T&gt; XY&lt;T&gt;::XY( T nx, T ny )
	{
		x = nx;
		y = ny;
	}

	template &lt;class T&gt; XY&lt;T&gt;::XY( const XY&lt;T&gt; &amp;other )
	{
		(*this) = other;
	}

	template &lt;class T&gt; XY&lt;T&gt;::~XY()
	{
	}

	template &lt;class T&gt; XY&lt;T&gt; &amp;XY&lt;T&gt;::operator=( const XY&lt;int&gt; &amp;right )
	{
		x = right.x;
		y = right.y;
		return (*this);
	}

	template &lt;class T&gt; XY&lt;T&gt; &amp;XY&lt;T&gt;::operator=( const XY&lt;double&gt; &amp;right )
	{
		x = right.x;
		y = right.y;
		return (*this);
	}
//Hier die Spezialisierung
	template &lt;&gt; XY&lt;int&gt; &amp;XY&lt;int&gt;::operator=( const XY&lt;double&gt; &amp;right )
	{
		x = Util::Round( right.x, 0 );
		y = Util::Round( right.y, 0 );
		return (*this);
	}
}

#endif
</code></pre>
<p>Ich weiß echt nicht woran das liegt. Danke für jede Hilfe</p>
<p>Cappo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/624975</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/624975</guid><dc:creator><![CDATA[Cappo]]></dc:creator><pubDate>Sat, 09 Oct 2004 17:35:44 GMT</pubDate></item><item><title><![CDATA[Reply to Template Spezialisierung -&amp;gt; Linker Problem on Sat, 09 Oct 2004 18:11:11 GMT]]></title><description><![CDATA[<p>Hab die Suchfunktion entdeckt;)</p>
<p>Mit dem Schlüsselwort inline klappts...Juhu!</p>
<p>Cappo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/625006</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/625006</guid><dc:creator><![CDATA[Cappo]]></dc:creator><pubDate>Sat, 09 Oct 2004 18:11:11 GMT</pubDate></item><item><title><![CDATA[Reply to Template Spezialisierung -&amp;gt; Linker Problem on Mon, 11 Oct 2004 10:36:05 GMT]]></title><description><![CDATA[<blockquote>
<p>Ich weiß echt nicht woran das liegt</p>
</blockquote>
<p>Eine explizite Spezialisierung ist kein Template. Für eine explizite Spezialisierung einer Funktion gelten die selben ODR-spezifischen Regeln wie für eine normale Funktion. Sprich: sie darf nur einmal pro Programm nicht einmal pro Übersetzungseinheit definiert werden.<br />
Lösung:<br />
Entwder du implementierst die Spezialisierung in einer cpp-Datei oder du deklarierst die Funktion inline und implementierst sie im Header. So wie du es jetzt ja gemacht hast.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/625852</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/625852</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Mon, 11 Oct 2004 10:36:05 GMT</pubDate></item></channel></rss>