title: How to copy/create derived class instance from a pointer to a polymorphic base class?
body: <p>I have been struggling with this kind of problem for a long time, so I decided to ask here.</p>
  
  <pre><code>class Base {
    virtual ~Base();
  };
  class Derived1 : public Base { ... };
  class Derived2 : public Base { ... };
  ...
  
  // Copies the instance of derived class pointed by the *base pointer
  Base* CreateCopy(Base* base);
  </code></pre>
  
  <p>The method should return a dynamically created copy, or at least store the object on stack in some data structure to avoid "returning address of a temporary" problem.</p>
  
  <p>The naive approach to implement the above method would be using multiple <code>typeid</code>s or <code>dynamic_cast</code>s in a series of if-statements to check for each possible derived type and then use the <code>new</code> operator. 
  Is there any other, better approach?</p>
  
  <p>P.S.: I know, that the this problem can be avoided using smart pointers, but I am interested in the minimalistic approach, without a bunch of libraries.</p>