Basically, I want to work with an array of pointers of a superclass and use them for subclasses.
I have a code that manipulates geometric forms. It's a "geometric forms" superclass, consisting of virtual methods and static ints.
Later in the code, I create inherited classes (circles, squares..), complementing the application.
I want to create an array of "geometric forms" pointer and pass the i'th item (index based on static attribute) to a specific sub-function, based on a switch case, responsible for methods for that geometric figure, with that i'th pointer.
Example: I want to work with squares, so I pass a menuSquares(geometricFroms *array[foo::getStatic()]){}...
Inside that function, I want to do:
ptrPassed = new Circle();
How can I do that?
I tried using a generic int pointer instead of a superclass type:
Class GeomFig {};
Class Circle : public GeomFig
{};
int main(){
GeomFig *arrayPtrs[100];
// selection of which shape the user wants to use
// ...
menuSquares(arrayPtrs[GeomFig::getStatic()]) {}...
}
// code def
menuSquares(GeomFig* &geomPtr)
{
geomPtr = new Circle();
}