title: base class function called even after virtual used
body: <p><a href="http://ideone.com/xc9yft" rel="nofollow noreferrer">Running code link</a> 
  I have a base class of object IObject from which 2 derived classes derivedObject and derivedObject2 are created . I have an IAlgoInterace base implementation of print which takes IObject  and then i derived derivedAlgo  from IAlgoInterace  from the same . The derived class derivedAlgo   overrides the print method with arguments of derived class derivedObject  &amp; derivedObject 2 . When i use print function to print object it is going to base class . </p>
  
  <p>Why is my derived class's right print called?
  What can be done to not change base IAlgoInterace and still achieve this functionality </p>
  
  <p>Aim: Implementing strategy design pattern and code pasted here is a small executable part of same. My aim is that the base class IAlgoInterace will never be needed to provide more information than that it has a print which can take all different kinds of derived class objects . Actual implementation ie in derived algo   will be based on derived object thats passed in it . print in derived algo will use data elements from the right object being passed in it . </p>
  
  <p>So    derivedAlgo class will print derivedObject2 differently from say derivedAlgo2 class </p>
  
  <pre><code>#include "stdafx.h"
  #include "iostream"
  using namespace std;
  
  class IObject
  {
  public:
       int data;
  };
  
  class derivedObject: public IObject
  {
  public:
      int dataAdditonal;
  };
  class derivedObject2: public IObject
  {
  public:
      int dataAdditonal;
  };
  
  
  class IAlgoInterace
  {
  
  public:
      virtual void print(IObject * object)
      {
          cout &lt;&lt; "\n base algo called";
      }
  };
  
  class derivedAlgo :  public IAlgoInterace
  {
      public:
      virtual void print(derivedObject * object)
      {
          cout &lt;&lt; "\n derived called for objct type 1 " ;
      }
      virtual void print(derivedObject2 * object)
      {
          cout &lt;&lt; "\n derived called for object type 2  " ;
      }
  };
  
  class derivedAlgo2 :  public IAlgoInterace
  {
      public:
      virtual void print(derivedObject * object)
      {
          cout &lt;&lt; "\n derived algo2  called for objct type 1 " ;
      }
      virtual void print(derivedObject2 * object)
      {
          cout &lt;&lt; "\n derived algo2  called for object type 2  " ;
      }
  };
  int _tmain(int argc, _TCHAR* argv[])
  {
      IObject * object = new derivedObject();
      IObject * object2 = new derivedObject2();
      IAlgoInterace * algo = new derivedAlgo();
  
      algo-&gt;print(object);
      algo-&gt;print(object2);
      int y ;
      cin &gt;&gt; y;
  }
  </code></pre>