title: Calling base class template constructor in C++
body: <p>I have a template base class which has a constructor for conversion from any other template instantiation of that class, like this:</p>
  
  <pre><code>template &lt;class T&gt;
  class FooBase
  {
  public:
  
      FooBase()
      {
      }
  
      template &lt;class U&gt;
      FooBase(const FooBase&lt;U&gt;&amp; other)
      {
          std::cout &lt;&lt; "FooBase&lt;U&gt;" &lt;&lt; std::endl;
      }
  };
  </code></pre>
  
  <p>Notice how there is no copy constructor defined.</p>
  
  <p>I then have a derived template class which does have a copy constructor, as well as the constructor used for conversion:</p>
  
  <pre><code>template &lt;class T&gt;
  class Foo : public FooBase&lt;T&gt;
  {
  public:
  
      Foo()
      {
      }
  
      Foo(const Foo&amp; other) :
          FooBase&lt;T&gt;(other)
      {
      }
  
      template &lt;class U&gt;
      Foo(const Foo&lt;U&gt;&amp; other) :
          FooBase&lt;T&gt;(other)
      {
      }
  };
  </code></pre>
  
  <p>Because <code>FooBase</code> doesn't have a copy constructor, this results in <code>FooBase&lt;T&gt;(other)</code> making a call to the compiler-generated copy constructor. Which means if I run this:</p>
  
  <pre><code>int main()
  {
      Foo&lt;int&gt; a;
      Foo&lt;int&gt; b(a);
  
      return 0;
  }
  </code></pre>
  
  <p>The output is <strong>nothing</strong>, when it should be <code>FooBase&lt;U&gt;</code>.</p>
  
  <p>Of course, I could try to solve the issue by creating a copy constructor in <code>FooBase</code> and using <a href="http://en.cppreference.com/w/cpp/language/initializer_list#Delegating_constructor" rel="noreferrer">delegating constructors</a>:</p>
  
  <pre><code>    FooBase(const FooBase&amp; other)
          : FooBase&lt;T&gt;(other)
      {
      }
  </code></pre>
  
  <p>But unfortunately that doesn't work, and it would result in a recursive call as the compiler helpfully points out:</p>
  
  <pre><code>warning C4717: 'FooBase&lt;int&gt;::FooBase&lt;int&gt;': recursive on all control paths, function will cause runtime stack overflow
  </code></pre>
  
  <p>So the only solution would be to duplicate the logic into both constructors.</p>
  
  <p>Is there any way around this that doesn't involve code duplication or a separate initialization function?</p>