I need to make a copy of GameMaster* thisMaster
so I can preform manipulations while still maintaining a "clean" copy. However, the way I'm doing it right now, when I make a change to copy
, it changes thisMaster
too.
void Move::possibleMoves(GameMaster* thisMaster)
{
GameMaster* copy = new GameMaster(*thisMaster);
}
How can I fix this?
edit: I created a copy constructor but am still having the same issue.
GameMaster::GameMaster(const GameMaster& gm)
{
for(int i=0;i<GAMETILES;i++)
{
gameTiles[i]=gm.gameTiles[i];
}
players=gm.players;
vertLines=gm.vertLines;
horLines=gm.horLines;
turn = gm.turn;
masterBoard=gm.masterBoard;
lastLegal=gm.lastLegal;
lastScore=gm.lastScore;
}
Here is the complete class definition for GameMaster:
Class GameMaster
{
public:
GameMaster(void);
GameMaster(const GameMaster& gm);
~GameMaster(void);
//functions
private:
std::vector <Player*> players;
std::vector <Line> vertLines;
std::vector <Line> horLines;
Tile gameTiles [GAMETILES];
std::vector <std::string>colors;
std::vector <std::string>shapes;
int turn;
Board masterBoard;
bool lastLegal;
int lastScore;
};
With the copy constructor, I am still having the issue with the Board changing values. Does it need a copy constructor too?