title: Constructor with extra template argument
body: <p>This question seems very closely related to the following, yet I do not fully understand it yet.</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/q/2861839/653152">Can the template parameters of a constructor be explicitly specified?</a></li>
  <li><a href="https://stackoverflow.com/q/13002368/653152">Template constructor in a class template - how to explicitly specify template argument for the 2nd parameter?</a></li>
  </ul>
  
  <hr>
  
  <p>I want to have a template class that does something non-trivial in the constructor, depending on another template type. A minimal example would be this here:</p>
  
  <pre><code>template &lt;typename A&gt;
  class Class {
    public:
      template &lt;typename B&gt;
      Class();
  
    private:
      int i;
  };
  
  template &lt;typename A, typename B&gt;
  Class&lt;A&gt;::Class() {
      B b;
  
      i = b.get_number();
  }
  </code></pre>
  
  <p>That does not compile with GCC:</p>
  
  <pre><code>$ env LC_ALL=C g++ --std=c++11 -c template.cpp 
  template.cpp:14:1: error: prototype for 'Class&lt;A&gt;::Class()' does not match any in class 'Class&lt;A&gt;'
   Class&lt;A&gt;::Class() {
   ^~~~~~~~
  template.cpp:7:5: error: candidate is: template&lt;class A&gt; template&lt;class B&gt; Class&lt;A&gt;::Class()
       Class();
       ^~~~~
  </code></pre>
  
  <p>Compiling with Clang gives other errors:</p>
  
  <pre><code>$ env LC_ALL=C clang++ --std=c++11 -c template.cpp 
  template.cpp:13:1: error: too many template parameters in template redeclaration
  template &lt;typename A, typename B&gt;
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  template.cpp:3:1: note: previous template declaration is here
  template &lt;typename A&gt;
  ^~~~~~~~~~~~~~~~~~~~~
  1 error generated.
  </code></pre>
  
  <p>I can get it to compile when I attach the template parameter <code>B</code> to the whole class.</p>
  
  <pre><code>template &lt;typename A, typename B&gt;
  class Class {
    public:
      Class();
  
    private:
      int i;
  };
  
  template &lt;typename A, typename B&gt;
  Class&lt;A, B&gt;::Class() {
      B b;
  
      i = b.get_number();
  }
  </code></pre>
  
  <p>Is there any way to contain the influence of template parameter <code>B</code> to the constructor? Or would I have to attach it to the whole class?</p>