title: Is it possible to creat a derived object from a base object through downcast?
body: <p>Base class</p>
  
  <pre><code>class Base
  {
  public:
      Base()=default;
      virtual void f(){cout &lt;&lt; "base class\n";}
      virtual ~Base(){}
  };
  </code></pre>
  
  <p>Derived class</p>
  
  <pre><code>class Derive : public Base
  {
  public:
      Derive()=default;
      void f() override {cout &lt;&lt; "derived class\n";}
  };
  </code></pre>
  
  <p>main function</p>
  
  <pre><code>int main()
  {
      Base* bsd = new Base;
      Derive* dru = new Derive;
  
      if(Derive* drd=dynamic_cast&lt;Derive*&gt;(bsd)){
          drd-&gt;f();
          cout &lt;&lt; "downcast successful\n";
      }else{
          cout &lt;&lt; "downcast failed\n";
      }
  
      if(Base* bsu=dynamic_cast&lt;Base*&gt;(dru)){
          bsu-&gt;f();
          cout &lt;&lt; "upcast successful\n";
      }else{
          cout &lt;&lt; "upcast failed\n";
      }
  
      delete bsd;
      delete dru;
  }
  </code></pre>
  
  <p>It turns out upcast works fine, while downcast failed. It seems makes sense that way. If the derived class contain member objects that are not declared in the base class and do not have default constructors, what gonna happen during downcast? </p>
  
  <p>Besides, the target pointer <code>*drd(*bsd)</code> created through <code>dynamic_cast</code> points to the same object with the pointer <code>*bsu(*dru)</code> to be cast. So delete once will be enough. We will not have a dangling pointer, right?</p>