Hello everyone, my first post. I am having some difficulty with correctly writing the Copy Constructor and overloading the assignment operator for some of my classes.
Here are the classes and their relevant data members.
class Card
{
//default copy ctor and assignemnt
//operator are all thats required
protected:
//bunch of ints
};
class CardContainer
{
//defauly copy ctor and
//assignment operator need
//to be overloaded
protected:
std::deque<Card> cards;
};
class Cascade: public CardContainer
{
//inherits its only data members
//from CardContainer
};
class Board
{
//default copy ctor and assignment
//operator need to be overloaded
private:
std::vector<CardContainer *> containers;
//initialised like this: containers.push_back(new Cascade));
};
int main
{
Board *board = new Board;
Board *board_backup = new Board;
//later on I want board_backup to have a copy
//of what board points to
board_backup = board;
//if later on I need to restore board to its original
//values then
delete board;
board = new Board(board_backup);
};
At certain points in the game, a copy of 'board' is given to 'board_backup'. I have written functions CopyContainers() and CopyCards(), both of which work. I have tried writing the copy ctor and assignment operators for class Board and class CardContainer but they do not work. I can post those attempts if you would like.
I would really appreciate any help with this, thanks for your time.