title: The reason why dynamic_cast doesn't work with non-polymorphic types
body: <p>With classes <code>B</code> and derived class <code>D</code>:</p>
  
  <pre><code>class B {
      int b;
  };
  
  
  class D : public B {
      int d;
  };
  
  
  D* d = new D();
  B* b = dynamic_cast&lt;B*&gt;(d);
  </code></pre>
  
  <p>the above will work fine&mdash;it's a simple upcasting. We're sure that whatever <code>b</code> is pointing at has the <code>B</code> class (sub-)object in it.</p>
  
  <p>However, </p>
  
  <pre><code>B* b = new D();
  D* d = dynamic_cast&lt;D*&gt;(b);
  </code></pre>
  
  <p>won't compile even though <code>b</code> points to a valid <code>D</code> instance&mdash;because the base class is not polymorphic. So adding just one, empty virtual method would solve the problem.</p>
  
  <p>The important question is why C++ requires the source type to be polymorphic? The only explanation I've found is <a href="https://stackoverflow.com/a/4644856/5539357">this</a>, but it merely states 'because that's how it's implemented internally' - at least in my eyes). People who designed <code>dynamic_cast</code> probably had some other reasons in mind - what were those?</p>