Hi all
Having a problem with a loss of member data when passing the object through to a seperate function. Relevant code fragments are:
Code:
Engine* theEngine = new Engine;
if (option == 1)
{
Connect4* C4game = new Connect4;
theEngine->setStarter(C4game->getPlayers(), C4game->getRows(), C4game->getColumns());
if (C4game->getPlayers()==1)
theEngine->RunSinglePlayer(C4game);
else
theEngine->RunMultiPlayer(C4game);
}
If I use "cout << C4game->getPlayers()" at this stage, it will show the number of players which has been entered (one or two). Next...
Code:
void Engine::RunSinglePlayer (Game* RelevantGame)
{
unsigned short CounterLocation;
PlayerGo = 1;
DrawGrid();
//...
}
If I were to write "RelevantGame->getPlayers()" at the start of this function, it will automatically show as zero - it's as though the member data was being wiped whilst the parameter is being passed. Between calling the RunSinglePlayer() function and actually arriving there, the data is disappearing.
Connect4 is a derived class from Game, and they both hold the same member data, so there should be no issue from that perspective (unless I've missed something?).
Anyone have any ideas why this is happening and how it can be resolved?
Many thanks! :-)