title: C++ virtual class from base pointer?
body: <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class Criminal {
  public:
      virtual void getType() = 0;
      virtual void getCrime() { cout &lt;&lt; "Unknown" &lt;&lt; endl; }
  };
  
  class Thug : public Criminal {
  public:
      void getType() { cout &lt;&lt; "Thugging" &lt;&lt; endl; }
      void getCrime() { cout &lt;&lt; "Gangsterism" &lt;&lt; endl; }
  };
  
  class Tupac : public Thug {
  public:
      void getType() { cout &lt;&lt; "Rapper" &lt;&lt; endl; }
      void getCrime() {
          cout &lt;&lt; "Being the best rapper to ever live" &lt;&lt; endl;
      }
  };
  
  int main() {
      Criminal* tupac = new Tupac();
      Criminal* thug = new Thug();
      Thug* poser = new Tupac(); // Thug has no virtual function
      //Criminal shouldNotCompile;
  
      tupac-&gt;getType();       
      tupac-&gt;getCrime();      
  
      thug-&gt;getType();        
      thug-&gt;getCrime();       
  
      poser-&gt;getType();       // I intend to call Thug::getType()
      poser-&gt;getCrime();      // I intend to call Thug::getCrime()
  
      delete tupac;
      delete thug;
      delete poser;
  
      getchar();
  
      return 0;
  }
  </code></pre>
  
  <p>The output is</p>
  
  <pre><code>Rapper
  Being the best rapper to ever live
  Thugging
  Gangsterism
  Rapper
  Being the best rapper to ever live
  </code></pre>
  
  <p>But I intend the poser calls from the Thug pointer to print "Thugging" and "Gangsterism."  </p>
  
  <p>How can I do this? I expected my code to work as is, because the "Thug" functions are not virtual, so shouldn't anything called from a Thug* pointer call the Thug functions?</p>
  
  <p>Why doesn't my code work the way I intended it to? Where is my confusion?</p>
  
  <p>What is an easy way to get my intended behavior?</p>