trouble with polymorphism
I'm trying to implement a generic minimax class so that I can just fill in the functions that change with different implementations. I tried declaring the functions that get overwritten as virtual void whatever()=0; but I need to instantiate the class in order to build a tree for the algorithm, so I went and changed all my pure virtual functions to be like virtual void whatever() {}. This works for calling the overwritten functions in everywhere but one spot. Like I said, I need ot instantiate a root for a tree, and I need to call functions on this class:
Code:
MiniMaxGame* root = new MiniMaxGame(player1Type,player2Type,boardw,boardh); //this is why they can't be pure virtual
root->expand(side); //doing this calls the empty expand in the base class, no good
I thought that I could get it to call the new function by putting it in a wrapper like this and using the same mechanism that works everywhere else:
Code:
void doExpand(int side) {expand(side);}
but this just gives the same problem. Is there some way to get around this, or should I look at a way to write the algorithm that doesn't require instantiating the base class?