My errors
[code]In constructor `MoveCommand::MoveCommand(Game*, void (Game::*)(Coordinate&))':|
will be initialized after
Command.h|31|warning: `void (Game::*MoveCommand::_moveFunc)(Coordinate&)'|
Command.C|3|warning: when initialized here|
In member function `virtualvoid MoveCommand::setMemento(CommandMemento*)':|
Command.C|7|error: invalid use of undefined type `struct CommandMemento'|
Command.h|7|error: forward declaration of `struct CommandMemento'|
Command.C|8|error: invalid use of undefined type `struct CommandMemento'|
Command.h|7|error: forward declaration of `struct CommandMemento'|
Command.C||In member function `virtual void MoveCommand::execute()':|
Command.C|12|error: expected primary-expression before '&' token| <my main prob>
Command.C|12|error: expected primary-expression before ')' token| <my main prob>
||=== Build finished: 6 errors, 3 warnings ===|
[/code]
I am unsure how to go about calling the function (Game::*moveFunc)(Coordinate&)
the command class is being build according to the COMMAND design pattern and the MEMENTO design pattern.
I want MoveCommand::execute to perform the function, by the errors, it seems im doing it wrong, how should i be doing this? and Please give me tips or tell me things that are pointless in my code, as this is the first time im using function pointers.
Another problem i have is creating a memento, i have a circular dependancy, where the memento needs to copy all the values of my command, while command needse to reinstate with the memento, so they both need to access each other's data members. I have declared both Memento and MoveCommand as friends of each other. Is this a bad idea? is there a better way to do this?
Even after reading your description a few times, I still do not understand what you are attempting to do here. The Command pattern and the Memento pattern are orthogonal. Having a MoveCommandMemento class doesn't make much sense to me.
Typically you would have your object (I'm assuming "Game" in this case) accept commands and retain mementos for history/undo. These are two separate bits of functionality. What would typically happen is that before executing the Command, the Game would save its state to a Memento, and only then call command.execute().
I would not have the commands themselves responsible for saving the Game state. Have the Game responsible for saving its own state.
But I could be way off base here because I don't clearly understand your goal.