Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think deriving your class from a base class is not relevant to the question here, that's a mere implementation detail. What you really seem to be after is if there's a way to partially specialize member functions, like the constructor. Do you want something like this?</p> <pre><code>template &lt;typename T, int N&gt; class Foo { Foo(); // general template &lt;typename U&gt; Foo&lt;U, 2&gt;(); // specialized, NOT REAL CODE }; </code></pre> <p>This doesn't work. You always have to specialize the entire class. The reason is simple: You have to know the full type of the class first <em>before</em> you even know which member functions exist. Consider the following simple situation:</p> <pre><code>template &lt;typename T&gt; class Bar { void somefunction(const T&amp;); }; template &lt;&gt; class Bar&lt;int&gt; { double baz(char, int); }; </code></pre> <p>Now <code>Bar&lt;T&gt;::somefunction()</code> depends on <code>T</code>, but the function only <em>exists</em> when <code>T</code> is not <code>int</code>, because <code>Bar&lt;int&gt;</code> is an entirely different class.</p> <p>Or consider even another specialization <code>template &lt;&gt; class Bar&lt;double&gt; : public Zip {};</code> -- even the polymorphic nature of a class can be entirely different in a specialization!</p> <p>So the only way you can provide <s>specializations</s> new declarations of members, including constructors, is by specializing the entire class. (You <em>can</em> specialize the <em>definition</em> of existing functions, see @Alf's answer.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload