title: Should I be using dynamic_cast<T> for copying?
body: <blockquote>
    <h3>Update 1:</h3>
    
    <p>Corrected nonsense code! Thanks for comments, I made a hash of the first snippet, oops.</p>
    
    <h3>Update 2:</h3>
    
    <p>Also updated question title, as the use of dynamic_cast has been pointed out as not necessary by answers.</p>
  </blockquote>
  
  <p>What I'm trying to achieve here is a deep copy using strong types; I want to be able to copy Class2 to another instance of Class2; however, I also want to use the CopyTo function from the Class1 which is the base. This idea comes from my C# experience, where usually I'd just make the return type generic (see C# snippet).</p>
  
  <pre><code>void Class1::CopyTo(Class1 *c1)
  {
      // Write data in to c1 from this instance.
      c1-&gt;exampleData = exampleData;
  }
  
  // Class2 inherits Class1
  Class2 *Class2::Copy()
  {
      Class2 *c2a = new Class2();
      CopyTo(c2a);
  
      Class2 *c2b = dynamic_cast&lt;Class2*&gt;(c2a);
      return c2a;
  }
  </code></pre>
  
  <p>And here's the way I'd so it in C#:</p>
  
  <pre><code>public class Class1
  {
      T Copy&lt;T&gt;()
          where T : Class1
      {
          /* Can't remember the best way to do this in C#;
           * basically if T was Class2 this would need to create
           * a new instance of that class, and the same goes for
           * Class1. */         
          T copy = createNewInstance();
  
          // Copy the data from this to 'copy'.
          copy.exampleData = exampleData;
  
          return copy;
      }
  }
  </code></pre>
  
  <p>Now, compared to the C# snippet, the C++ snippet feel smelly. Is it possible to do this without pointers, or is this way best practice?</p>