Specialized template class (descended from general case) with a template constructor using a dependent type
<p>I need to make a templated class constructor take a dependent type (on the templated class types). This works fine, unless I have a specialization of the templated class, in which case the constructor doesn't seem to be found. And if I reimplement the constructor in the specialized subclass, I don't seem to be able to initialize the base class either through the constructor or directly.</p>

<p>Is there any way to preserve this relatively narrow interface outside of the class?</p>

<pre><code>class T1 {};
class T2 {};

// KeyType
template &lt;typename SELECT&gt;
class KeyType {
};

// Declarations
template &lt;typename SELECT = T1&gt;
class TestTemplate {
protected:
    TestTemplate() {}
    KeyType&lt;SELECT&gt; k;
public:
    TestTemplate(KeyType&lt;SELECT&gt; const &amp;key) : k(key) {}
};

template &lt;&gt;
class TestTemplate&lt;T2&gt; : public TestTemplate&lt;T1&gt; {
};


int main() {

    KeyType&lt;T2&gt; key;
    TestTemplate&lt;T2&gt; foo(key);
    return 0;
}
</code></pre>

<p>After staring at it for a bit, I realize that the problem is that I can't just arbitrarily convert the <code>KeyType&lt;T2&gt;</code> to a <code>KeyType&lt;T1&gt;</code> for the <code>TestTemplate&lt;T1&gt;</code> baseclass.</p>

<p>g++ gives:</p>

<pre><code>g++ -std=c++14 -O2 -Wall -pedantic -pthread main.cpp &amp;&amp; ./a.out
main.cpp: In function 'int main()':
main.cpp:27:29: error: no matching function for call to 'TestTemplate&lt;T2&gt;::TestTemplate(KeyType&lt;T2&gt;&amp;)'
     TestTemplate&lt;T2&gt; foo(key);
                             ^
main.cpp:20:7: note: candidate: TestTemplate&lt;T2&gt;::TestTemplate()
 class TestTemplate&lt;T2&gt; : public TestTemplate&lt;T1&gt; {
       ^
main.cpp:20:7: note:   candidate expects 0 arguments, 1 provided
main.cpp:20:7: note: candidate: constexpr TestTemplate&lt;T2&gt;::TestTemplate(const TestTemplate&lt;T2&gt;&amp;)
main.cpp:20:7: note:   no known conversion for argument 1 from 'KeyType&lt;T2&gt;' to 'const TestTemplate&lt;T2&gt;&amp;'
main.cpp:20:7: note: candidate: constexpr TestTemplate&lt;T2&gt;::TestTemplate(TestTemplate&lt;T2&gt;&amp;&amp;)
main.cpp:20:7: note:   no known conversion for argument 1 from 'KeyType&lt;T2&gt;' to 'TestTemplate&lt;T2&gt;&amp;&amp;'
</code></pre>