I have an abstract base class called CBase
and two other classes CDerived1
and CDerived2
that are derived from CBase
.
How would I now create a dynamic array (i.e. add and delete elements at runtime) of CBase
? Of course, this array would just contain objects of the derived classes because the base class is abstract.
I would try something like this:
CBase* arr;
arr = (CBase*) malloc(arrSize*sizeof(CBase));
It feels like this solution would get complicated when I want to resize the array as I want. How would I do that? Or do you recommend any other kind of array for that?