title: Check which subclass an object is in C++?
body: <p>Given that there are the following struct types:</p>
  
  <pre><code>struct A {};
  struct B : A {};
  struct C : A {};
  struct D : B {};
  </code></pre>
  
  <p>And we have a piece of code:</p>
  
  <pre><code>A a = f();
  </code></pre>
  
  <p>How would you check what type the struct actually is? i.e. is it <code>A</code>, <code>B</code>, <code>C</code> or <code>D</code>?</p>
  
  <p>I can give the context in which I'm trying to use the answer for this if needed, but I don't think that's needed.</p>