I have an abstract base class in C++ and need to create an array to store objects which are subclasses of it. I use pointers to the subclasses since each member of the array needs to be of the same size. Currently I am declaring and initializing my array like this:
BaseClass *array[];
...
array =
{
&SubClass1(...),
&SubClass2(...),
...
&SubClass3(...)
};
This is giving me the following when I try to compile:
warning: taking address of temporary
error: too many initializers for ‘BaseClass* [0]’
What's the proper way of doing this?