title: Can someone explain the benefits of polymorphism?
body: <p>So I understand pretty much how it works, but I just can't grasp what makes it useful.  You still have to define all the separate functions, you still have to create an instance of each object, so why not just call the function from that object vs creating the object, creating a pointer to the parent object and passing the derived objects reference, just to call a function?  I don't understand the benefits of taking this extra step.</p>
  
  <p>Why do this:</p>
  
  <pre><code>class Parent
  {
      virtual void function(){};
  };
  
  class Derived : public Parent
  {
      void function()
      {
      cout &lt;&lt; "derived";
      }
  };
  
  int main()
  {
      Derived foo;
      Parent* bar = &amp;foo;
      bar-&gt;function();
      return -3234324;
  }
  </code></pre>
  
  <p>vs this:</p>
  
  <pre><code>class Parent
  {
      virtual void function(){};
  };
  
  class Derived : public Parent
  {
      void function()
      {
      cout &lt;&lt; "derived";
      }
  };
  
  int main()
  {
      Derived foo;
      foo.function();
      return -3234324;
  }
  </code></pre>
  
  <p>They do exactly the same thing right?  Only one uses more memory and more confusion as far as I can tell.</p>