title: Call derived class method from base class reference
body: <pre><code>class Material
  {
  public:
   void foo()
   {
    cout &lt;&lt; "Class Material";
   }
  };
  
  class Unusual_Material : public Material
  {
  public:
   void foo()
   {
    cout &lt;&lt; "Class Unusual_Material";
   }
  };
  
  int main()
  {
   Material strange = Unusual_Material();
   strange.foo(); //outputs "Class Material" 
  
   return 0;
  }
  </code></pre>
  
  <p>I would like for this to result in the "Class Unusual_Material" being displayed to the console. Is there a way I can achieve this? In my program I have a class Material from which other more specific materials are derived. The method Material::foo() represents a method in Material that is adequate for most materials, but occationally, another foo() needs to be defined for a material with unusual properties. </p>
  
  <p>All objects in my program contain a Material field. In the event that they are assigned an unusual material, I would like the derived, unusual foo to be called.</p>
  
  <p>This is probably either pretty easy, or impossible, but I can't figure it out either way.</p>
  
  <p>Thanks</p>