<?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[Problem mit partieller Spezialisierung]]></title><description><![CDATA[<p>Servus,</p>
<p>ich möchte eine Memberfuktion ihre Überladung aufrufen lassen, wenn die Klasse mit einer Länge &gt; 0 instantiiert wurde. Etwa so:</p>
<pre><code class="language-cpp">template &lt;typename T, size_t length = 0&gt;
class Foo {
    void bar();
    void bar(size_t n);
};

template &lt;size_t length&gt;
void Foo&lt;std::vector&lt;char&gt;, length&gt;::bar() { bar(length); }
</code></pre>
<p>gcc quittiert mir das mit einem</p>
<pre><code>error: invalid use of undefined type `class Foo&lt;std::vector&lt;char, std::allocator&lt;char&gt; &gt;, length&gt;' 
error: template definition of non-template `void Foo&lt;std::vector&lt;char, std::allocator&lt;char&gt; &gt;, length&gt;::bar()' 
In member function `void Foo&lt;std::vector&lt;char, std::allocator&lt;char&gt; &gt;, length&gt;::bar()': 
error: there are no arguments to `bar' that depend on a template parameter, so a declaration of `bar' must be available 
error: (if you use `-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
</code></pre>
<p>Ich müsste jetzt in die Bibliothek laufen und mir den Alexandrescu holen, denn ich erinnere mich schwach, dass es da ein Konstrukt gibtt, was genau diesen Mechanismus erlaubt.</p>
<p>Weiß das jemand aus dem Kopf?</p>
<p>Philipp</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/270091/problem-mit-partieller-spezialisierung</link><generator>RSS for Node</generator><lastBuildDate>Sun, 30 Aug 2026 13:46:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/270091.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 06 Jul 2010 12:48:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit partieller Spezialisierung on Tue, 06 Jul 2010 12:48:22 GMT]]></title><description><![CDATA[<p>Servus,</p>
<p>ich möchte eine Memberfuktion ihre Überladung aufrufen lassen, wenn die Klasse mit einer Länge &gt; 0 instantiiert wurde. Etwa so:</p>
<pre><code class="language-cpp">template &lt;typename T, size_t length = 0&gt;
class Foo {
    void bar();
    void bar(size_t n);
};

template &lt;size_t length&gt;
void Foo&lt;std::vector&lt;char&gt;, length&gt;::bar() { bar(length); }
</code></pre>
<p>gcc quittiert mir das mit einem</p>
<pre><code>error: invalid use of undefined type `class Foo&lt;std::vector&lt;char, std::allocator&lt;char&gt; &gt;, length&gt;' 
error: template definition of non-template `void Foo&lt;std::vector&lt;char, std::allocator&lt;char&gt; &gt;, length&gt;::bar()' 
In member function `void Foo&lt;std::vector&lt;char, std::allocator&lt;char&gt; &gt;, length&gt;::bar()': 
error: there are no arguments to `bar' that depend on a template parameter, so a declaration of `bar' must be available 
error: (if you use `-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
</code></pre>
<p>Ich müsste jetzt in die Bibliothek laufen und mir den Alexandrescu holen, denn ich erinnere mich schwach, dass es da ein Konstrukt gibtt, was genau diesen Mechanismus erlaubt.</p>
<p>Weiß das jemand aus dem Kopf?</p>
<p>Philipp</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1922215</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922215</guid><dc:creator><![CDATA[PhilippM]]></dc:creator><pubDate>Tue, 06 Jul 2010 12:48:22 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit partieller Spezialisierung on Tue, 06 Jul 2010 13:05:09 GMT]]></title><description><![CDATA[<p>Du mußt die Spezialisierung (glaub ich) vorher deklarieren:</p>
<pre><code class="language-cpp">template &lt;typename T, size_t length = 0&gt;
class Foo {
public:
    void bar();
    void bar(int n);
};

template &lt;size_t length&gt;
class Foo&lt;std::vector&lt;char&gt;, length&gt; {
public:
    void bar();
};

template &lt;size_t length&gt;
void Foo&lt;std::vector&lt;char&gt;, length&gt;::bar() { bar(length);}
</code></pre>
<p>Gruß,<br />
CSpille</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1922226</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922226</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Tue, 06 Jul 2010 13:05:09 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit partieller Spezialisierung on Tue, 06 Jul 2010 13:11:30 GMT]]></title><description><![CDATA[<p>Bißchen unpraktisch, wenn die Klasse vier Konstruktoren und noch vier andere Memberfunktionen enthält - muss ich die dann alle kopieren ?? Das ging iwie einfacher.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1922232</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922232</guid><dc:creator><![CDATA[PhilippM]]></dc:creator><pubDate>Tue, 06 Jul 2010 13:11:30 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit partieller Spezialisierung on Tue, 06 Jul 2010 13:31:11 GMT]]></title><description><![CDATA[<p>Dreh den Spieß doch um und spezialisier die 0-Methode:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;

template &lt;typename T, size_t length&gt;
class Foo
{
    public:
        void bar() { this-&gt;bar(length); }
        void bar(size_t n){ std::cout &lt;&lt; &quot;Nicht null, sondern &quot; &lt;&lt; length &lt;&lt; &quot;...&quot; &lt;&lt; std::endl; }
};

template &lt;&gt;
void Foo&lt;std::vector&lt;char&gt;, 0&gt;::bar() { std::cout &lt;&lt; &quot;Null...&quot; &lt;&lt; std::endl; }

int main()
{
    Foo&lt;std::vector&lt;char&gt;, 0&gt; f;
    Foo&lt;std::vector&lt;char&gt;, 1&gt; f1;

    f.bar();    // &quot;Null...&quot;
    f1.bar();   // &quot;Nicht null, sondern 1...&quot;

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1922250</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922250</guid><dc:creator><![CDATA[Spielumdreher]]></dc:creator><pubDate>Tue, 06 Jul 2010 13:31:11 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit partieller Spezialisierung on Tue, 06 Jul 2010 13:47:00 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/10503">@PhilippM</a>:</p>
<p>Falls du ne schöne Lösung findest (keinen Workaround), dann bitte das<br />
posten nicht vergessen <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/1922267</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922267</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Tue, 06 Jul 2010 13:47:00 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit partieller Spezialisierung on Tue, 06 Jul 2010 18:34:49 GMT]]></title><description><![CDATA[<p>Template-Metaprogrammierung:</p>
<pre><code class="language-cpp">struct FooImplImpl
{
	void bar(size_t n);
};

template &lt;size_t length&gt;
struct FooImpl : FooImplImpl
{
	using FooImplImpl::bar;

	void bar()
	{
		bar(length);
	}
};

template &lt;&gt;
struct FooImpl&lt;0&gt; : FooImplImpl
{
	using FooImplImpl::bar;

	void bar()
	{
		bla();
	}
};

template &lt;typename T, size_t length = 0&gt;
struct Foo : FooImpl&lt;length&gt;
{
};
</code></pre>
<p>Aber weil die C++ler immer zu kompliziert denken:</p>
<pre><code class="language-cpp">template &lt;typename T, size_t length = 0&gt;
struct Foo
{
	void bar()
	{
		if (length &gt; 0)
			bar(length);
		else
			bla();
	}

	void bar(size_t n);
};
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f576.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--sunglasses"
      title=":sunglasses:"
      alt="🕶"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1922410</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1922410</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 06 Jul 2010 18:34:49 GMT</pubDate></item></channel></rss>