<?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[Partielle Spezialisierung einer Templateklassen Methode]]></title><description><![CDATA[<p>Hallo zusammen<br />
Ich möchte eine einzelne Methode eines Klassentemplates partiell spezialisieren (nicht überladen). Ist dies in C++ mögliche und wenn ja wie?</p>
<p>Mit überladen habe ich es auch versucht:</p>
<pre><code class="language-cpp">template&lt;class TK,class TI&gt; bool RedBlackTree&lt;TK,TI&gt;::KeyExists(string *Key) const;
</code></pre>
<p>und erhalte folgenden Fehler:</p>
<blockquote>
<p>1&gt;c:\users\samuel\desktop\projekte\serenity\serenity\development\serenity\resourceservice.cpp(1072) : error C2668: 'Dictionary&lt;TK,TI&gt;::KeyExists' : ambiguous call to overloaded function<br />
1&gt; with<br />
1&gt; [<br />
1&gt; TK=string *,<br />
1&gt; TI=Resource *<br />
1&gt; ]<br />
1&gt; c:\users\samuel\desktop\projekte\serenity\serenity\development\serenity\datastructures.h(1030): could be 'bool Dictionary&lt;TK,TI&gt;::KeyExists(string <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="😉"
    /> const'<br />
1&gt; with<br />
1&gt; [<br />
1&gt; TK=string *,<br />
1&gt; TI=Resource *<br />
1&gt; ]<br />
1&gt; c:\users\samuel\desktop\projekte\serenity\serenity\development\serenity\datastructures.h(1029): or 'bool Dictionary&lt;TK,TI&gt;::KeyExists(const TK &amp;) const'<br />
1&gt; with<br />
1&gt; [<br />
1&gt; TK=string *,<br />
1&gt; TI=Resource *<br />
1&gt; ]<br />
1&gt; while trying to match the argument list '(string *)'</p>
</blockquote>
<p>Mein Versuch einer partiellen Spezialisierung ist leider auch kläglich gescheitert:</p>
<pre><code class="language-cpp">template&lt;string*,class TI&gt; bool RedBlackTree&lt;string*,TI&gt;::KeyExists(string *Key) const;
</code></pre>
<blockquote>
<p>1&gt;c:\users\samuel\desktop\projekte\serenity\serenity\development\serenity\redblacktree.cpp(5038) : error C3860: template argument list following class template name must list parameters in the order used in template parameter list<br />
1&gt;c:\users\samuel\desktop\projekte\serenity\serenity\development\serenity\redblacktree.cpp(5038) : error C3855: 'RedBlackTree&lt;TK,TI&gt;': template parameter 'TK' is incompatible with the declaration</p>
</blockquote>
<p>Weiss vielleicht jemand, wie das Teil richtig geht? Ich verwende Visual Studio 2008</p>
<p>Mfg Samuel</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/262658/partielle-spezialisierung-einer-templateklassen-methode</link><generator>RSS for Node</generator><lastBuildDate>Sun, 06 Sep 2026 12:09:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/262658.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 09 Mar 2010 14:25:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Partielle Spezialisierung einer Templateklassen Methode on Tue, 09 Mar 2010 14:25:13 GMT]]></title><description><![CDATA[<p>Hallo zusammen<br />
Ich möchte eine einzelne Methode eines Klassentemplates partiell spezialisieren (nicht überladen). Ist dies in C++ mögliche und wenn ja wie?</p>
<p>Mit überladen habe ich es auch versucht:</p>
<pre><code class="language-cpp">template&lt;class TK,class TI&gt; bool RedBlackTree&lt;TK,TI&gt;::KeyExists(string *Key) const;
</code></pre>
<p>und erhalte folgenden Fehler:</p>
<blockquote>
<p>1&gt;c:\users\samuel\desktop\projekte\serenity\serenity\development\serenity\resourceservice.cpp(1072) : error C2668: 'Dictionary&lt;TK,TI&gt;::KeyExists' : ambiguous call to overloaded function<br />
1&gt; with<br />
1&gt; [<br />
1&gt; TK=string *,<br />
1&gt; TI=Resource *<br />
1&gt; ]<br />
1&gt; c:\users\samuel\desktop\projekte\serenity\serenity\development\serenity\datastructures.h(1030): could be 'bool Dictionary&lt;TK,TI&gt;::KeyExists(string <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="😉"
    /> const'<br />
1&gt; with<br />
1&gt; [<br />
1&gt; TK=string *,<br />
1&gt; TI=Resource *<br />
1&gt; ]<br />
1&gt; c:\users\samuel\desktop\projekte\serenity\serenity\development\serenity\datastructures.h(1029): or 'bool Dictionary&lt;TK,TI&gt;::KeyExists(const TK &amp;) const'<br />
1&gt; with<br />
1&gt; [<br />
1&gt; TK=string *,<br />
1&gt; TI=Resource *<br />
1&gt; ]<br />
1&gt; while trying to match the argument list '(string *)'</p>
</blockquote>
<p>Mein Versuch einer partiellen Spezialisierung ist leider auch kläglich gescheitert:</p>
<pre><code class="language-cpp">template&lt;string*,class TI&gt; bool RedBlackTree&lt;string*,TI&gt;::KeyExists(string *Key) const;
</code></pre>
<blockquote>
<p>1&gt;c:\users\samuel\desktop\projekte\serenity\serenity\development\serenity\redblacktree.cpp(5038) : error C3860: template argument list following class template name must list parameters in the order used in template parameter list<br />
1&gt;c:\users\samuel\desktop\projekte\serenity\serenity\development\serenity\redblacktree.cpp(5038) : error C3855: 'RedBlackTree&lt;TK,TI&gt;': template parameter 'TK' is incompatible with the declaration</p>
</blockquote>
<p>Weiss vielleicht jemand, wie das Teil richtig geht? Ich verwende Visual Studio 2008</p>
<p>Mfg Samuel</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1866563</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1866563</guid><dc:creator><![CDATA[Ishildur]]></dc:creator><pubDate>Tue, 09 Mar 2010 14:25:13 GMT</pubDate></item><item><title><![CDATA[Reply to Partielle Spezialisierung einer Templateklassen Methode on Tue, 09 Mar 2010 14:27:27 GMT]]></title><description><![CDATA[<p>Funktionstemplates können nicht partiell spezialisiert werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1866564</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1866564</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Tue, 09 Mar 2010 14:27:27 GMT</pubDate></item><item><title><![CDATA[Reply to Partielle Spezialisierung einer Templateklassen Methode on Tue, 09 Mar 2010 14:31:33 GMT]]></title><description><![CDATA[<p>Hmmm OK,<br />
Wie kann ich dieses Problem lösen? Ich möchte ja natürlich nicht die ganzen Datenstrukturen noch einmal implementieren nur wegen den C-Strings...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1866568</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1866568</guid><dc:creator><![CDATA[Ishildur]]></dc:creator><pubDate>Tue, 09 Mar 2010 14:31:33 GMT</pubDate></item><item><title><![CDATA[Reply to Partielle Spezialisierung einer Templateklassen Methode on Tue, 09 Mar 2010 14:36:58 GMT]]></title><description><![CDATA[<p>Was genau hast du denn vor, wozu brauchst du eine Spezialisierung? Könnte etwas wie type traits dein Problem lösen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1866572</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1866572</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Tue, 09 Mar 2010 14:36:58 GMT</pubDate></item><item><title><![CDATA[Reply to Partielle Spezialisierung einer Templateklassen Methode on Tue, 09 Mar 2010 14:38:18 GMT]]></title><description><![CDATA[<p>Nun ja, die C-String Variante benötigt ein strcmp und kein &lt; operator. Das ist mein Problem <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/1866573</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1866573</guid><dc:creator><![CDATA[Ishildur]]></dc:creator><pubDate>Tue, 09 Mar 2010 14:38:18 GMT</pubDate></item><item><title><![CDATA[Reply to Partielle Spezialisierung einer Templateklassen Methode on Tue, 09 Mar 2010 14:52:26 GMT]]></title><description><![CDATA[<p>Dann benutz doch ein templated Function object zum Vergleichen:</p>
<pre><code class="language-cpp">template&lt;typename T&gt;
struct comparator
{
   bool operator()( const T&amp; op1, const T&amp; op2 ) const
   {
      return op1 &lt; op2;
   }
};

template&lt;&gt;
struct comparator&lt;char*&gt;
{
   bool operator()( const char* op1, const char* op2 ) const
   {
      return strcmp( op1, op2 ) &lt; 0;
   }
};
</code></pre>
<p>In deiner Dictionary Klasse legst du ein Objekt davon an und benutzt es zum Vergleichen:</p>
<pre><code class="language-cpp">template&lt;typename TK, typename TI&gt;
class Dictionary
{
   comparator&lt;TK&gt; compare_;
   ...
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1866579</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1866579</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Tue, 09 Mar 2010 14:52:26 GMT</pubDate></item><item><title><![CDATA[Reply to Partielle Spezialisierung einer Templateklassen Methode on Tue, 09 Mar 2010 14:50:00 GMT]]></title><description><![CDATA[<p>Also die Find, KeyExists usw. benutzt den &lt; operator für die Sortierung. Das Problem ist nun, dass dies bei einem C-String nutzlos ist, weil ich ja nicht überprüfen will, welche Startadresse kleiner ist, sondern ich benötige einen lexikalischen Vergleich (strcmp)...</p>
<p>Es muss doch eine Möglichkeit geben, dies zu handeln?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1866580</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1866580</guid><dc:creator><![CDATA[Ishildur]]></dc:creator><pubDate>Tue, 09 Mar 2010 14:50:00 GMT</pubDate></item><item><title><![CDATA[Reply to Partielle Spezialisierung einer Templateklassen Methode on Tue, 09 Mar 2010 14:52:34 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/18927">@DocShoe</a><br />
Clever... <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/1866582</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1866582</guid><dc:creator><![CDATA[Ishildur]]></dc:creator><pubDate>Tue, 09 Mar 2010 14:52:34 GMT</pubDate></item><item><title><![CDATA[Reply to Partielle Spezialisierung einer Templateklassen Methode on Tue, 09 Mar 2010 14:56:44 GMT]]></title><description><![CDATA[<p>Ishildur schrieb:</p>
<blockquote>
<p>Also die Find, KeyExists usw. benutzt den &lt; operator für die Sortierung. Das Problem ist nun, dass dies bei einem C-String nutzlos ist, weil ich ja nicht überprüfen will, welche Startadresse kleiner ist, sondern ich benötige einen lexikalischen Vergleich (strcmp)...</p>
<p>Es muss doch eine Möglichkeit geben, dies zu handeln?</p>
</blockquote>
<p><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>
<p>Ja genau das habe ich doch vorgeschlagen. Für char* wird strcmp benutzt, für alle anderen Typen operator&lt;().</p>
<p>PS:<br />
Kannst ja mal gucken, ob std::less nicht genau das ist, was du brauchst. Es könnte bereits eine Spezialisierung für C-Strings geben.</p>
<p>PPS:<br />
Nö, std::less kanns nicht, zumindest nicht in meiner Implementation der STL</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1866583</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1866583</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Tue, 09 Mar 2010 14:56:44 GMT</pubDate></item><item><title><![CDATA[Reply to Partielle Spezialisierung einer Templateklassen Methode on Tue, 09 Mar 2010 15:07:18 GMT]]></title><description><![CDATA[<p>Ja unsere Beiträge hatten sich überschnitten. Ich finde deinen Lösungsansatz super und bin gerade dabei, ihn zu implementieren <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/1866585</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1866585</guid><dc:creator><![CDATA[Ishildur]]></dc:creator><pubDate>Tue, 09 Mar 2010 15:07:18 GMT</pubDate></item></channel></rss>