title: How does dynamic_cast fail?
body: <p>According to what I read, performing a wrong run-time dynamic_cast can either throw a bad_cast exception or return zero.</p>
  
  <p>Is it correct to say that it will return zero if you are casting pointers?</p>
  
  <p>i.e:</p>
  
  <pre><code>class Base { virtual void a(){} };
  class Derived: public Base {};
  
  int main () {
    Base *base = new Base();
    dynamic_cast&lt;Derived*&gt;(base);
    return 0;
  } 
  </code></pre>
  
  <p>And that it will throw an bad_cast exception when casting objects?</p>
  
  <p>i.e:</p>
  
  <pre><code>class Base { virtual void a(){} };
  class Derived: public Base {};
  
  int main () {
    Base base;
    Base&amp; ref = base;
    dynamic_cast&lt;Derived&amp;&gt;(ref);
    return 0;
  }
  </code></pre>