How to create a dynamic array of an Abstract class?

You would need to create an array of pointers to Cat:

Cat** catArray = new Cat*[200];

Even if the base class Cat was concrete, you would still run headlong into object slicing if you created an array of Cat.

Note that you should probably use a std::vector instead of an array, and should probably use smart pointers to ensure your code is exception safe.


By creating an aray of pointers to Cat, as in

 Cat** catArray = new Cat*[200];

Now you can put your WildCat, HouseCat etc instances at various locations in the array for example

 catArray[0] = new WildCat();
 catArray[1] = new HouseCat();
 catArray[0]->catchMice(); 
 catArray[1]->catchMice();

Couple of caveats, when done
a) Don't forget deleting the instances allocated in catArray as in delete catArray[0] etc.
b) Don't forget to delete the catArray itself using

 delete [] catArray;

You should also consider using vector to automate b) for you


You cannot round up the cats in fixed size cages, because the compiler has no way of knowing how big the cats will be, nor (metaphor failure) how to initialize them. You are going need to do something like initialize the array to null cat-pointers or something, and herd them later.