title: How to debug a std::bad_cast exception
body: <pre class="lang-cpp prettyprint-override"><code>class GAGenome {
    virtual void method(){};
  };
  
  template &lt;class T&gt;
  class GAArray {
  };
  
  template &lt;class T&gt;
  class GA1DArrayGenome : public GAArray&lt;T&gt;, public GAGenome {
  };
  
  int main() {
    GA1DArrayGenome&lt;float&gt; genome;
    const GAGenome &amp; reference = genome;
    auto cast = dynamic_cast&lt;const GA1DArrayGenome&lt;int&gt; &amp;&gt;(reference);
  }
  </code></pre>
  
  <p>This obviously wrong program (since template parameter is different)  crashes with</p>
  
  <pre><code>terminate called after throwing an instance of 'std::bad_cast'
    what():  std::bad_cast
  Aborted (core dumped)
  </code></pre>
  
  <p>Is there a way how to get precise diagnostics of what went wrong, beyond the runtime error message? Something, that can point out the int/float mistake to me? I am looking for a descriptive error message like</p>
  
  <blockquote>
    <p><code>const GA1DArrayGenome&lt;float&gt; &amp;</code> cannot be cast to <code>const GA1DArrayGenome&lt;int&gt; &amp;</code></p>
  </blockquote>
  
  <p>Even better, since C++ types can get hairy at times, the tool could notice the precise discrepancy in the template parameter.</p>