title: Creating derived class instance using base class instance
body: <p>I have a base class instance, there is a derived class that inherits from the base class, I want to transform the base instance into derived instance, (if possible without copying anything (maybe sending to the derived class a reference of the base class)) how can I achieve that? </p>
  
  <p>Note: I need this because I'm using factory design pattern which identify the derived class needed to be created using a parameter located in the base instance.</p>
  
  <pre><code>//class A
  //class B: public A (pure virtual)
  //class C: public B
  
  B BFactory::makeB(A &amp;a) {
      int n=a.getN();
      if(n==1){
          return new C();
      }
  }
  </code></pre>
  
  <p>Thanks.</p>