C++ template issue to Pull Up the Builder pattern into a configuration? <p>I have an algorithm that requires a large number of parameters (i.e. configuration) as part of its constructor and also requires some clearly defined creational steps. Therefore I have created a <a href="http://en.wikipedia.org/wiki/Builder_pattern" rel="nofollow">Builder Pattern</a> implementation that allows to set the needed parameters and create the intermediate and final instance e.g.</p> <pre><code>// somewhere class SomeAlgo { public: SomeAlgo(double a, double b, double c, double d, double e /* etc */); ; </code></pre> <p>Now I define the Builder to be e.g.</p> <pre><code>class SomeAlgoBuilder { public: SomeAlgo&amp; createResult() { /* TODO: */ } virtual SomeAlgoBuilder&amp; creationStep1() = 0; virtual SomeAlgoBuilder&amp; creationStep2() = 0; virtual SomeAlgoBuilder&amp; creationStep3() = 0; // example setter note the builder returns *this SomeAlgoBuilder&amp; setA(double a) { a_ = a; return *this; } SomeAlgoBuilder&amp; setB(double b) { b_ = b; return *this; } // etc }; </code></pre> <p>At this point everything looks ok but now I would like to <code>Pull Up</code> the setters of the builder into a <code>SomeAlgoConfig</code> class so that I can also cover the use-case of passing around a simple configuration instead of a convoluted long list of parameters. This simple configuration is what in Java is known as a Value Object or Bean. The new Builder would be like this:</p> <pre><code>// not "is a" config but need the implementation inheritance // &gt;&gt;&gt;&gt;&gt;&gt; note the need to pass SomeAlgoBuilder as template class SomeAlgoBuilder : private SomeAlgoConfig&lt;SomeAlgoBuilder&gt; { public: SomeAlgo&amp; createResult() { /* TODO: */ } virtual SomeAlgoBuilder&amp; creationStep1() = 0; virtual SomeAlgoBuilder&amp; creationStep2() = 0; virtual SomeAlgoBuilder&amp; creationStep3() = 0; }; </code></pre> <p>Now the <code>SomeAlgoConfig</code> implementation:</p> <pre><code>template&lt;T&gt; class SomeAlgoConfig { T&amp; setA(double a) { a_ = a; return *static_cast&lt;T*&gt;(this); } T&amp; setB(double b) { b_ = b; return *static_cast&lt;T*&gt;(this); } // etc } </code></pre> <p>and the intent is to be used like this:</p> <pre><code>SomeAlgoConfig config; // &lt;&lt;&lt; here it won't compile because it misses the T parameter config.setA(a).setB(b).setC(c); </code></pre> <p>This will do the trick I guess. However, whenever I'd like to use <code>SomeAlgoConfig</code> on its own (outside the context of a Builder) e.g. to pass it as parameter I need to declare it with a template parameter which would be itself <code>SomeAlgoConfig&lt;SomeAlgoConfig&gt;</code>. How can I define it in a way that it defaults to itself as template type? e.g. doing this doesn't work: <code>template&lt;typename T = SomeAlgoConfig&gt; class SomeAlgoConfig</code> because the <code>SomeAlgoConfig</code> is not yet known at that point. </p>