title: Create derived class from base class object
body: <p>I have base class which is generic parser of some data, and I have multiple derived classes which provide specific access interface to data contained in parser. I can determine the type of derived class only after all data is parsed, since it depends on the hierarchy (there is the tree of base classes, which needs to be fully populated to determine derived class for each base).</p>
  
  <p>What is the best way to create derived class from base class, avoiding unnecessary copying of the data? As of now, I'm creating derived using copy constructor of base (as below):</p>
  
  <pre><code>class Base
  {
  };
  
  class Derived : public Base
  {
    Derived(const Base &amp;base)
    : Base(base)
    {
    }
  };
  </code></pre>
  
  <p>, but this requires copying all the base data which is no necessary - I want base class to become derived without copying and deleting it if possible.</p>
  
  <p>EDIT:</p>
  
  <p>Base parser parses data file and stores data generically as map >, while derived classes provide specific access interface depending on hte actual data type stored. Derived classes may change and more can be added.</p>