title: I want a vector of derived class pointers as base class pointers
body: <p>In C++, the vector class stores an array of objects. In this case, I am storing pointers to derived class objects (Dogs). At some point, I want to treat this vector as pointers to objects of the base class (Animals). This is the "right"/non controversial way right? Why can't I do this?</p>
  
  <pre><code>#include &lt;vector&gt;
  using namespace std;
  
  class Animal { }; 
  class Dog : public Animal { };
  
  int main(int argc, char *argv[]) {
      vector&lt;Dog*&gt; dogs;
      dogs.push_back(new Dog());
      dogs.push_back(new Dog());
      vector&lt;Animal*&gt; animals = dogs; // This doesn't seem to work.
  
      // This is really what I want to do...
      vector&lt;Animal*&gt; all_animals[] = {dogs, cats, birds};
  }
  </code></pre>
  
  <p>The error:</p>
  
  <pre><code>Untitled.cpp:11:18: error: no viable conversion from 'vector&lt;class Dog *&gt;' to 'vector&lt;class Animal *&gt;'
      vector&lt;Animal*&gt; animals = dogs;
                      ^         ~~~~
  /usr/include/c++/4.2.1/bits/stl_vector.h:231:7: note: candidate constructor not viable: no known conversion from 'vector&lt;Dog *&gt;' to 'const std::vector&lt;Animal *, std::allocator&lt;Animal *&gt; &gt; &amp;' for 1st argument
    vector(const vector&amp; __x)
    ^
  </code></pre>