title: invalid covariant return type for templated child class
body: <p>I have a child class that inherits from a parent class, but the child also picks up a template argument. Both classes have a 'clone' function that just calls their copy constructor. I want to make the copy virtual so that the child class will always call it's own copy.</p>
  
  <p>Here is a simplified version of the problem:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class Parent
  {
  public:
      virtual Parent foo() { cout &lt;&lt; "Parent Foo\n"; return *this; }
  };
  
  template &lt;class T&gt;
  class Child : public Parent
  {
  public:
      Child&lt;T&gt; foo() { cout &lt;&lt; "Child Foo\n"; return *this; }
  };
  
  int main()
  {
      Child&lt;int&gt; c;
  
      c.foo();
  
      return 0;
  }
  </code></pre>
  
  <p>It seems that the Child class should be covariant with the Parent class. What am I missing? Is there a way to still keep the virtual function and the template? Thanks.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Perhaps my previous example was too simple. Here is an expanded simple example:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class Parent
  {
  public:
      Parent(){}
      virtual Parent clone() const { return Parent(*this); }
  private:
      Parent( Parent const&amp; cpy ) { };
  };
  
  template &lt;class T&gt;
  class Child : public Parent
  {
  public:
      Child(){}
      Child&lt;T&gt; clone() const { return Child&lt;T&gt;(*this); }
  private:
      Child( Child&lt;T&gt; const&amp; cpy ) {};
  };
  
  int main()
  {
      Child&lt;int&gt; c;
      Parent* pc = &amp;c;
      pc-&gt;clone();
  
      return 0;
  }
  </code></pre>
  
  <p>I would like the copy to always be an actual copy of the class by making copy virtual.
  I wanted to avoid returning a pointer, but it looks like I will be forced to return pointers to avoid the slicing problem mentioned by Dieter Lücking.</p>