I want a vector of derived class pointers as base class pointers
问题 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? #include <vector> using namespace std; class Animal { }; class Dog : public Animal { }; int main(int argc, char *argv[]) { vector<Dog*> dogs; dogs.push_back(new Dog()); dogs.push_back(new Dog()); vector<Animal*