<?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[[solved] template spezialisierung funktioniert nicht]]></title><description><![CDATA[<p>hi zusammen!</p>
<p>ich hab folgendes problem (mit msvs2005+sp1): ich hab 'ne template methode in der klasse Logger</p>
<pre><code class="language-cpp">#ifndef __LOGCLIENT_H__
#define __LOGCLIENT_H__
class LogClient
{

	//...

	template&lt;class T&gt; 
	void LogClient::Log( T &amp;t, LOGLEVEL logLevel )
	{
		if( logLevel &gt; this-&gt;logLevel )
			return;

		if( !this-&gt;logger )
			this-&gt;logger = Logger::GetSingleton();

		this-&gt;logger-&gt;Log( t, this, logLevel );
	}
</code></pre>
<p>und davon 'ne spezialisierung für stringstreams:</p>
<pre><code class="language-cpp">template&lt;&gt;
	void LogClient::Log&lt;std::stringstream&gt;( std::stringstream &amp;ss, LOGLEVEL logLevel )
	{
		this-&gt;Log( ss.str(), logLevel );
	}
};
#endif
</code></pre>
<p>das funktioniert soweit, nur wenn ich das file in mehreren .cpps includiere schreit der linker ab dem zweiten file:</p>
<p>Linker schrieb:</p>
<blockquote>
<p>Error 1 error LNK2005: &quot;public: void __thiscall psi::LogClient::Log&lt;class std::basic_stringstream&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; &gt;(class std::basic_stringstream&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; &amp;,enum psi::LOGLEVEL)&quot; (??<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>L</mi><mi>o</mi><mi>g</mi><mi mathvariant="normal">@</mi><mi>V</mi><mo>?</mo></mrow><annotation encoding="application/x-tex">Log@V?</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">L</span><span class="mord mathit">o</span><span class="mord mathit" style="margin-right:0.03588em;">g</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.22222em;">V</span><span class="mclose">?</span></span></span></span>basic_stringstream@DU?<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>c</mi><mi>h</mi><mi>a</mi><mi>r</mi><mi mathvariant="normal">_</mi><mi>t</mi><mi>r</mi><mi>a</mi><mi>i</mi><mi>t</mi><mi>s</mi><mi mathvariant="normal">@</mi><mi>D</mi><mi mathvariant="normal">@</mi><mi>s</mi><mi>t</mi><mi>d</mi><mi mathvariant="normal">@</mi><mi mathvariant="normal">@</mi><mi>V</mi><mo>?</mo></mrow><annotation encoding="application/x-tex">char\_traits@D@std@@V?</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:1.00444em;vertical-align:-0.31em;"></span><span class="base textstyle uncramped"><span class="mord mathit">c</span><span class="mord mathit">h</span><span class="mord mathit">a</span><span class="mord mathit" style="margin-right:0.02778em;">r</span><span class="mord mathrm" style="margin-right:0.02778em;">_</span><span class="mord mathit">t</span><span class="mord mathit" style="margin-right:0.02778em;">r</span><span class="mord mathit">a</span><span class="mord mathit">i</span><span class="mord mathit">t</span><span class="mord mathit">s</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.02778em;">D</span><span class="mord mathrm">@</span><span class="mord mathit">s</span><span class="mord mathit">t</span><span class="mord mathit">d</span><span class="mord mathrm">@</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.22222em;">V</span><span class="mclose">?</span></span></span></span>allocator@D@2@@std@@@LogClient@psi@@QAEXAAV?<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>b</mi><mi>a</mi><mi>s</mi><mi>i</mi><mi>c</mi><mi mathvariant="normal">_</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>i</mi><mi>n</mi><mi>g</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>e</mi><mi>a</mi><mi>m</mi><mi mathvariant="normal">@</mi><mi>D</mi><mi>U</mi><mo>?</mo></mrow><annotation encoding="application/x-tex">basic\_stringstream@DU?</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:1.00444em;vertical-align:-0.31em;"></span><span class="base textstyle uncramped"><span class="mord mathit">b</span><span class="mord mathit">a</span><span class="mord mathit">s</span><span class="mord mathit">i</span><span class="mord mathit">c</span><span class="mord mathrm" style="margin-right:0.02778em;">_</span><span class="mord mathit">s</span><span class="mord mathit">t</span><span class="mord mathit" style="margin-right:0.02778em;">r</span><span class="mord mathit">i</span><span class="mord mathit">n</span><span class="mord mathit" style="margin-right:0.03588em;">g</span><span class="mord mathit">s</span><span class="mord mathit">t</span><span class="mord mathit" style="margin-right:0.02778em;">r</span><span class="mord mathit">e</span><span class="mord mathit">a</span><span class="mord mathit">m</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.02778em;">D</span><span class="mord mathit" style="margin-right:0.10903em;">U</span><span class="mclose">?</span></span></span></span>char_traits@D@std@@V?$allocator@D@2@@std@@W4LOGLEVEL@1@@Z) already defined in Main.obj NetClient.obj</p>
</blockquote>
<p>kann mir beim besten willen net erklären was ihm das nicht passt. HILFÄÄÄH!! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/180450/solved-template-spezialisierung-funktioniert-nicht</link><generator>RSS for Node</generator><lastBuildDate>Thu, 01 Oct 2026 20:28:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/180450.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 02 May 2007 21:36:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [solved] template spezialisierung funktioniert nicht on Thu, 20 Mar 2008 09:24:16 GMT]]></title><description><![CDATA[<p>hi zusammen!</p>
<p>ich hab folgendes problem (mit msvs2005+sp1): ich hab 'ne template methode in der klasse Logger</p>
<pre><code class="language-cpp">#ifndef __LOGCLIENT_H__
#define __LOGCLIENT_H__
class LogClient
{

	//...

	template&lt;class T&gt; 
	void LogClient::Log( T &amp;t, LOGLEVEL logLevel )
	{
		if( logLevel &gt; this-&gt;logLevel )
			return;

		if( !this-&gt;logger )
			this-&gt;logger = Logger::GetSingleton();

		this-&gt;logger-&gt;Log( t, this, logLevel );
	}
</code></pre>
<p>und davon 'ne spezialisierung für stringstreams:</p>
<pre><code class="language-cpp">template&lt;&gt;
	void LogClient::Log&lt;std::stringstream&gt;( std::stringstream &amp;ss, LOGLEVEL logLevel )
	{
		this-&gt;Log( ss.str(), logLevel );
	}
};
#endif
</code></pre>
<p>das funktioniert soweit, nur wenn ich das file in mehreren .cpps includiere schreit der linker ab dem zweiten file:</p>
<p>Linker schrieb:</p>
<blockquote>
<p>Error 1 error LNK2005: &quot;public: void __thiscall psi::LogClient::Log&lt;class std::basic_stringstream&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; &gt;(class std::basic_stringstream&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; &amp;,enum psi::LOGLEVEL)&quot; (??<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>L</mi><mi>o</mi><mi>g</mi><mi mathvariant="normal">@</mi><mi>V</mi><mo>?</mo></mrow><annotation encoding="application/x-tex">Log@V?</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">L</span><span class="mord mathit">o</span><span class="mord mathit" style="margin-right:0.03588em;">g</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.22222em;">V</span><span class="mclose">?</span></span></span></span>basic_stringstream@DU?<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>c</mi><mi>h</mi><mi>a</mi><mi>r</mi><mi mathvariant="normal">_</mi><mi>t</mi><mi>r</mi><mi>a</mi><mi>i</mi><mi>t</mi><mi>s</mi><mi mathvariant="normal">@</mi><mi>D</mi><mi mathvariant="normal">@</mi><mi>s</mi><mi>t</mi><mi>d</mi><mi mathvariant="normal">@</mi><mi mathvariant="normal">@</mi><mi>V</mi><mo>?</mo></mrow><annotation encoding="application/x-tex">char\_traits@D@std@@V?</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:1.00444em;vertical-align:-0.31em;"></span><span class="base textstyle uncramped"><span class="mord mathit">c</span><span class="mord mathit">h</span><span class="mord mathit">a</span><span class="mord mathit" style="margin-right:0.02778em;">r</span><span class="mord mathrm" style="margin-right:0.02778em;">_</span><span class="mord mathit">t</span><span class="mord mathit" style="margin-right:0.02778em;">r</span><span class="mord mathit">a</span><span class="mord mathit">i</span><span class="mord mathit">t</span><span class="mord mathit">s</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.02778em;">D</span><span class="mord mathrm">@</span><span class="mord mathit">s</span><span class="mord mathit">t</span><span class="mord mathit">d</span><span class="mord mathrm">@</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.22222em;">V</span><span class="mclose">?</span></span></span></span>allocator@D@2@@std@@@LogClient@psi@@QAEXAAV?<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>b</mi><mi>a</mi><mi>s</mi><mi>i</mi><mi>c</mi><mi mathvariant="normal">_</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>i</mi><mi>n</mi><mi>g</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>e</mi><mi>a</mi><mi>m</mi><mi mathvariant="normal">@</mi><mi>D</mi><mi>U</mi><mo>?</mo></mrow><annotation encoding="application/x-tex">basic\_stringstream@DU?</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:1.00444em;vertical-align:-0.31em;"></span><span class="base textstyle uncramped"><span class="mord mathit">b</span><span class="mord mathit">a</span><span class="mord mathit">s</span><span class="mord mathit">i</span><span class="mord mathit">c</span><span class="mord mathrm" style="margin-right:0.02778em;">_</span><span class="mord mathit">s</span><span class="mord mathit">t</span><span class="mord mathit" style="margin-right:0.02778em;">r</span><span class="mord mathit">i</span><span class="mord mathit">n</span><span class="mord mathit" style="margin-right:0.03588em;">g</span><span class="mord mathit">s</span><span class="mord mathit">t</span><span class="mord mathit" style="margin-right:0.02778em;">r</span><span class="mord mathit">e</span><span class="mord mathit">a</span><span class="mord mathit">m</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.02778em;">D</span><span class="mord mathit" style="margin-right:0.10903em;">U</span><span class="mclose">?</span></span></span></span>char_traits@D@std@@V?$allocator@D@2@@std@@W4LOGLEVEL@1@@Z) already defined in Main.obj NetClient.obj</p>
</blockquote>
<p>kann mir beim besten willen net erklären was ihm das nicht passt. HILFÄÄÄH!! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1277855</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1277855</guid><dc:creator><![CDATA[iko79]]></dc:creator><pubDate>Thu, 20 Mar 2008 09:24:16 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] template spezialisierung funktioniert nicht on Wed, 02 May 2007 22:12:41 GMT]]></title><description><![CDATA[<p>Eine explizite Spezialisierung eines Templates ist <em>kein</em> Template. Es gilt also die übliche ODR. Die Definition darf nur einmal existieren, oder du machst eine inline Funktion draus. Wenn du die Definition in einer .cpp Datei durchführst, musst du sie allerdings trotzdem im Header deklarieren - andernfalls würde der Compiler in allen anderen Übersetzungseinheiten das Primärtemplate anwenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1277863</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1277863</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 02 May 2007 22:12:41 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] template spezialisierung funktioniert nicht on Wed, 02 May 2007 22:27:57 GMT]]></title><description><![CDATA[<p>asoooh! das wusst' ich nicht, danke...</p>
<p>camper schrieb:</p>
<blockquote>
<p>musst du sie allerdings trotzdem im Header deklarieren</p>
</blockquote>
<p>hm. wie schreibt ma das syntaktisch an? oO</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1277871</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1277871</guid><dc:creator><![CDATA[iko79]]></dc:creator><pubDate>Wed, 02 May 2007 22:27:57 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] template spezialisierung funktioniert nicht on Wed, 02 May 2007 22:36:44 GMT]]></title><description><![CDATA[<p>iko79 schrieb:</p>
<blockquote>
<p>asoooh! das wusst' ich nicht, danke...</p>
<p>camper schrieb:</p>
<blockquote>
<p>musst du sie allerdings trotzdem im Header deklarieren</p>
</blockquote>
<p>hm. wie schreibt ma das syntaktisch an? oO</p>
</blockquote>
<p>Wie jede andere Funktionsdeklaration. Du lässt einfach den Funktionsrumpf weg, und schreibst ein Semikolon dafür <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>
<pre><code class="language-cpp">template&lt;&gt;
void LogClient::Log&lt;std::stringstream&gt;( std::stringstream &amp;ss, LOGLEVEL logLevel );
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1277873</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1277873</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 02 May 2007 22:36:44 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] template spezialisierung funktioniert nicht on Wed, 02 May 2007 23:01:29 GMT]]></title><description><![CDATA[<p>so gehts, ausserhalb der klasse, hast recht.<br />
...hätte das nämlich innerhalb der klasse versucht:</p>
<pre><code class="language-cpp">class LogClient
	{
		//...
		template&lt;class T&gt; 
		void Log( T &amp;t, LOGLEVEL logLevel );

		template&lt;&gt;
		void Log&lt;std::stringstream&gt;( std::stringstream &amp;ss, LOGLEVEL logLevel );
	};
</code></pre>
<p>und dann in der cpp implementiert:</p>
<pre><code class="language-cpp">template&lt;&gt;
void LogClient::Log&lt;std::stringstream&gt;( std::stringstream &amp;ss, LOGLEVEL logLevel )
{
	this-&gt;Log( ss.str(), logLevel );
}
</code></pre>
<p>hast vielleicht da auch noch schnell a idee was daran falsch ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1277875</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1277875</guid><dc:creator><![CDATA[iko79]]></dc:creator><pubDate>Wed, 02 May 2007 23:01:29 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] template spezialisierung funktioniert nicht on Thu, 03 May 2007 00:45:05 GMT]]></title><description><![CDATA[<p>okay, scheinbar nicht...</p>
<p>danke trotzdem, hast mir sehr geholfen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1277896</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1277896</guid><dc:creator><![CDATA[iko79]]></dc:creator><pubDate>Thu, 03 May 2007 00:45:05 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] template spezialisierung funktioniert nicht on Thu, 03 May 2007 01:47:14 GMT]]></title><description><![CDATA[<p>Was bekommst du denn für einen Fehler?<br />
Ansich sollte das schon gehen...</p>
<p>Das &quot;LogClient::&quot; in der Definition von LogClient selbst ist allerdings unnötig und AFAIK auch falsch... der MSVC frisst das nur &quot;trotzdem&quot; (auch mit ausgeschalteten Extensions!?!).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1277903</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1277903</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Thu, 03 May 2007 01:47:14 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] template spezialisierung funktioniert nicht on Thu, 03 May 2007 06:00:15 GMT]]></title><description><![CDATA[<p>... sorry falscher thread <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/1277921</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1277921</guid><dc:creator><![CDATA[muffmolch]]></dc:creator><pubDate>Thu, 03 May 2007 06:00:15 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] template spezialisierung funktioniert nicht on Sun, 18 Nov 2007 00:16:39 GMT]]></title><description><![CDATA[<p>*edit*</p>
<p>okay, ich bin ein blödmann. was hier vorhin gestanden is ging nicht weil ich ein using namespace vergessen hab. ma muss ma aber zu gute halten: die fehlermeldungen vom compiler waren ja auch net ganz aufschlussreich... <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>jedoch hab i jetzt ein ganz anderes problem: i möcht eine template-klasse schreiben, von der der konstruktor und eine methode spezialisiert sind. diese spezialisierungen müssen in cpps ausgelagert werden, weils sonst linker-errors hagelt. soweit noch klar. weiters müssen die spezialisierungen im headerfile deklariert werden. auch logisch. nur gehts irgendwie nicht, jedenfalls krieg ichs nicht hin, die schreibweise hunzt. hab jetzt mehrere durchprobiert:</p>
<p>path.h</p>
<pre><code class="language-cpp">#ifndef __PATH_H__
#define __PATH_H__

#include &lt;ogrequaternion.h&gt;

namespace psi
{
	template &lt;class T&gt;
	class Path
	{
	public:
		virtual ~Path()	{}

		virtual T Calc( float progress )	=	0;
	};

	template &lt;class T&gt;
	class LinearPath : public Path&lt;T&gt;
	{
	private:
		T	t0;
		T	t1;

	public:
		LinearPath( T start, T end ) : t0( start ), t1( end - start )	{}

		T Calc( float progress );

		template &lt;&gt;
		LinearPath( Ogre::Quaternion start, Ogre::Quaternion end );
		template &lt;&gt;
		Ogre::Quaternion Calc( float progress );
	};

	template &lt;class T&gt;
	T LinearPath&lt;T&gt;::Calc( float progress )
	{
		return ( this-&gt;t0 + this-&gt;t1 * progress );
	}

}
#endif
</code></pre>
<p>path.cpp</p>
<pre><code class="language-cpp">#include &quot;Path.h&quot;

using namespace psi;

template &lt;&gt;
LinearPath&lt;Ogre::Quaternion&gt;::LinearPath( Ogre::Quaternion start, Ogre::Quaternion end ) : t0( start ), t1( end )	{}

template &lt;&gt;
Ogre::Quaternion LinearPath&lt;Ogre::Quaternion&gt;::Calc( float progress )
{
	return Ogre::Quaternion::Slerp( progress, this-&gt;t0, this-&gt;t1, true );
}
</code></pre>
<p>wenn ich path.h in zwei files includiere krieg ich nen linker error.</p>
<blockquote>
<p>Error 1 error LNK2005: &quot;public: virtual class Ogre::Quaternion __thiscall psi::LinearPath&lt;class Ogre::Quaternion&gt;::Calc(float)&quot; (?Calc@?$LinearPath@VQuaternion@Ogre@@@psi@@UAE?AVQuaternion@Ogre@@M@Z) already defined in mainTest.obj Path.obj</p>
</blockquote>
<p>kann ma wer sagen wie die syntax ausschauen muss dass sowas klappt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405124</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405124</guid><dc:creator><![CDATA[iko79]]></dc:creator><pubDate>Sun, 18 Nov 2007 00:16:39 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] template spezialisierung funktioniert nicht on Sun, 18 Nov 2007 10:17:22 GMT]]></title><description><![CDATA[<p>Deklarier die Funktion als 'inline', das sollte funktionieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405195</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405195</guid><dc:creator><![CDATA[Konrad Rudolph]]></dc:creator><pubDate>Sun, 18 Nov 2007 10:17:22 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] template spezialisierung funktioniert nicht on Sun, 18 Nov 2007 10:47:38 GMT]]></title><description><![CDATA[<p>Das ist aber trotzdem noch nicht korrekt.</p>
<p>Der 2. Konstruktor ist eine normale Überladung:</p>
<pre><code class="language-cpp">LinearPath( Ogre::Quaternion start, Ogre::Quaternion end );
</code></pre>
<p>Und du kannst keine 2 gleichen Funktionen mit unterschiedlichen Rückgabewerten deklarieren:</p>
<pre><code class="language-cpp">T Calc( float progress );

Ogre::Quaternion Calc( float progress );
</code></pre>
<p>Welche soll er dann bei &quot;t.Calc(0.0f)&quot; aufrufen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405209</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405209</guid><dc:creator><![CDATA[Th]]></dc:creator><pubDate>Sun, 18 Nov 2007 10:47:38 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] template spezialisierung funktioniert nicht on Sun, 18 Nov 2007 21:54:07 GMT]]></title><description><![CDATA[<p>danke für die antworten. i hab jetzt inzwischen nach endlosem herumprobieren hinbekommen indem ich die gesamte klasse spezialisiert hab. habs anders nicht hinbekommen. i schreib das hier nur rein, damit ich - wenn ich 's nächste mal das selbe problem hab (und das passiert bestimmt) - die lösung find.</p>
<pre><code class="language-cpp">template &lt;class T&gt;
	class LinearPath : public Path&lt;T&gt;
	{
	private:
		T	t0;
		T	t1;

	public:
		LinearPath()					{	this-&gt;t0 = 0; this-&gt;t1 = 0;		}
		LinearPath( T start, T end )	{	this-&gt;Set( start, end );		}

		T Calc( float progress );

		void Set( T start, T end )		{	this-&gt;t0 = start;	this-&gt;t1 = end - start;			}

		T GetStart()					{	return ( this-&gt;t0 );				}
		T GetEnd()						{	return ( this-&gt;t0 + this-&gt;t1 );		}
	};

	template &lt;class T&gt;
	T LinearPath&lt;T&gt;::Calc( float progress )
	{
		return ( this-&gt;t0 + this-&gt;t1 * progress );
	}

	template &lt;&gt;
	class LinearPath&lt;Ogre::Quaternion&gt; : public Path&lt;Ogre::Quaternion&gt;
	{
	private:
		Ogre::Quaternion	t0;
		Ogre::Quaternion	t1;

	public:
		LinearPath( Ogre::Quaternion start, Ogre::Quaternion end )	{	this-&gt;Set( start, end );	}
		Ogre::Quaternion Calc( float progress );

		void Set( Ogre::Quaternion start, Ogre::Quaternion end )	{	this-&gt;t0 = start;	this-&gt;t1 = end;	}
		Ogre::Quaternion GetStart()									{	return this-&gt;t0;					}
		Ogre::Quaternion GetEnd()									{	return this-&gt;t1;					}
	};
</code></pre>
<pre><code class="language-cpp">#include &quot;Path.h&quot;

using namespace psi;

Ogre::Quaternion LinearPath&lt;Ogre::Quaternion&gt;::Calc( float progress )
{
	return Ogre::Quaternion::Slerp( progress, this-&gt;t0, this-&gt;t1, true );
}
</code></pre>
<p>Th schrieb:</p>
<blockquote>
<p>Welche soll er dann bei &quot;t.Calc(0.0f)&quot; aufrufen?</p>
</blockquote>
<p>das is ja ka überladung sondern a spezialisierung. er soll natürlich die methode verwenden, die für die aktuell verwendete klasse kompiliert worden ist -&gt; also in dem fall</p>
<pre><code class="language-cpp">LinearPath&lt;Ogre::Quaternion&gt; path( q1, q2 );
q = path.Calc( 0.75f );
</code></pre>
<p>eben die spezialisierte, in dem fall</p>
<pre><code class="language-cpp">LinearPath&lt;int&gt; path( 10, 120 );
i = path.Calc( 0.75f );
</code></pre>
<p>eine für int kompilierte version.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405598</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405598</guid><dc:creator><![CDATA[iko79]]></dc:creator><pubDate>Sun, 18 Nov 2007 21:54:07 GMT</pubDate></item></channel></rss>