title: C++ Casting From Parent to Child After Passing as a Function?
body: <p>I was wondering if this (above title) is exactly possible when it comes to inheriting from an interface within C++.</p>
  
  <pre><code>class Animal
  {
     public:
        virtual void Eat(Animal&amp; a) = 0; //Function that attempts to eat an animal.
  }
  
  class Dog : Animal
  {
     public:
         void Eat(Animal&amp; a);
  }
  
  void Dog::Eat(Animal&amp; a)
  {
      Dog d = (Dog) a;
      // Do something.
  }
  
  int main()
  {
     Dog dog1 = Dog();
     Dog dog2 = Dog();
  
     dog1.Eat(dog2);
     return;
  }
  </code></pre>
  
  <p>So basically, I know that the animal that my dog is going to be eating is only other dogs (<strong>in all cases ever, not just in this specific example</strong>). However, I am inheriting from a purely virtual class Animal which requires me to define the function with the Animal parameter.</p>
  
  <p>I know that having a parameter as Animal causes the function Dog::Eat to think that the parameter is an Animal and not a Dog. However, considering that the data for the object to be represented as a Dog is still <em>there</em> I am pretty sure that there is a way to establish (cast, etc) the Animal as a Dog, I just don't know how and I am not quite sure how to search.</p>
  
  <p>So I am wondering how I would do this. I am pretty sure that you can use a dynamic cast or a reinterpret cast, but I am under the impression that you typically want to minimize the use of these casts <em>if you can</em>. I am pretty new to Object Oriented within C++ since I used to mainly use only C.</p>