title: Not Understanding Polymorphic Functions
body: <p>I am trying to create an array of objects whose class' all inherit from a Base class. Since I am just learning C++ after using Python, this was my first encounter with object slicing. From what I have read I should use pointers to the objects instead of instances of the objects themselves, but I can't seem to make it work.</p>
  
  <p>For example, why does this program output:
  1
  1
  instead of:
  1
  2</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class A{
  public:
      int getNumber(){
          return(1);
      }
  };
  
  class B : public A{
  public:
      int getNumber(){
          return(2);
      }
  };
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      A* list[2];
      list[0] = new A();
      list[1] = new B();
  
      std::cout &lt;&lt; list[0]-&gt;getNumber() &lt;&lt; std::endl;
      std::cout &lt;&lt; list[1]-&gt;getNumber() &lt;&lt; std::endl;
  
      int x;
      std::cin &gt;&gt; x;
      return 0;
  }
  </code></pre>