title: How to return a templated derived class instead of base class in an overridden function?
body: <pre><code>#include &lt;iostream&gt;
  
  template &lt;typename T&gt;
  class A {};
  
  template &lt;typename T&gt;
  class B : public A&lt;T&gt; {};
  
  class C
  {
      virtual A&lt;int&gt; func() = 0;
  };
  
  class D : public C
  {
      virtual B&lt;int&gt; func() override
      {
          return B&lt;int&gt;{};
      }
  };
  </code></pre>
  
  <p>Here <code>B</code> inherits from <code>A</code> and the template argument is <code>int</code> for both of the return values. Why can't I just return <code>B&lt;int&gt;</code> instead of <code>A&lt;int&gt;</code>?</p>