I have several objects that represent different parts of the maze that inherit from one abstract class, and they all have a choice of draw method: console(), file(), or gui(). Each concrete class has these methods, but each draws a slightly different piece of the maze. I have an array of pointers to the abstract class that are objects of the various concrete subclasses.
I want to pass a function pointer as a parameter to a draw function that will draw each individual part of the maze from the array of pointers to the abstract class. I want to do something like this:
void draw(void (*drawFunc)(ostream &), ostream & out)
{
for (int i=0; i<abstractArray.length; i++)
abstractArray[i]->(*drawFunc(out));
}
void pickDraw()
{
// Let user choose option and store in string option
if (option == "console")
draw(console, cout);
else if (option == "file")
draw(file, fout);
else
draw(gui, cout);
}
I do not know, however, how to pass a pointer to a function inside an unknown subclass of an abstract class. Is it possible? Should I give up on this approach? If anymore clarification is needed, just let me know.
Thank you for the help!


Sign In
Create Account


Back to top









