title: How do i determine what a base class is by providing a function that returns its type in C++?
body: <p>(Prob a duplicate)</p>
  <p>I would really like to have function <code>type()</code> returning some value that can symbolize either class but it seems like it doesn't work that way.</p>
  <pre><code>#include &lt;iostream&gt;
  
  class A {
  public:
      char type() { return 'A'; }
  };
  
  class B : public A {
  public:
      char type() { return 'B'; }
  };
  
  class C : public A {
  public:
      char type() { return 'C'; }
  };
  
  auto main() -&gt; int{
    A *b = new B;
    A *c = new C;
  
    std::cout &lt;&lt; b-&gt;type() &lt;&lt; &quot;\n&quot;; // leads to 'A' but expecting 'B'
    std::cout &lt;&lt; c-&gt;type() &lt;&lt; &quot;\n&quot;; // leads to 'A' but expecting 'C'
  
  
    return 0;
  }
  </code></pre>