title: Pass subclasses to a function that takes their superclass
body: <p>Let's say I have three classes - <code>Animal</code>, <code>Cat</code> and <code>Dog</code>, where <code>Cat</code> and <code>Dog</code> are subclasses of <code>Animal</code> (this does sound like the first lectures, but it's not homework I promise, just simplifying the real code)</p>
  
  <pre><code>Dog* spike = new Dog(); 
  Cat* puss = new Cat();   
  
  int main(int argc, char** argv)
  {
      function(spike, puss);
      return 0;
  }
  
  void function(Animal *pet, Animal *pet2)
  {
     magic-&gt;andSoForth();
  }
  </code></pre>
  
  <p>Now this generates the following error:</p>
  
  <pre class="lang-none prettyprint-override"><code>Cannot convert parameter 1 from 'Dog *' to 'Animal'
    No constructor could take the source type,
      or constructor overload resolution was ambiguous
  </code></pre>
  
  <p>Changing the parameters to exactly match generates similar errors, only that it says it can't convert from a class to the same class.</p>
  
  <p>I have successfully called the subclasses functions and members that they inherit from the superclass, so I know that this, logically, should work. I just don't know in what twisted way this language want me to bend logic.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Solution happen to be: pointers confuse everyone.</p>
  
  <ul>
  <li>Declare pointers.</li>
  <li>Send pointers as arguments to a function that does NOT handle pointers.</li>
  </ul>
  
  <p>In my example, I sent the "not-pointers" to the function that wanted pointers, I just switched that. Now it works fine.</p>