title: Why does this static C++ cast work?
body: <p>Imagine this code:</p>
  
  <pre><code>class Base {
   public:
    virtual void foo(){}
  };
  
  class Derived: public Base {
    public:
      int i;
      void foo() override {}
      void do_derived() {
        std::cout &lt;&lt; i;
      }
  };
  
  int main(){
    Base *ptr = new Base;
    Derived * static_ptr = static_cast&lt;Derived*&gt;(ptr);
    static_ptr-&gt;i = 10;  // Why does this work?
    static_ptr-&gt;foo(); // Why does this work?
    return 0;
  }
  </code></pre>
  
  <p>Why do I get the result 10 on the console? I wonder because I thought the ptr is a pointer to a base object. Therefore the object doesn't contain a int i or the method <code>do_derived()</code>. Is a new derived-Object automatically generated?</p>
  
  <p>When I declare a virtual <code>do_derived()</code> method in the Base class too, then this one is chosen, but why?</p>