diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-11-10 13:42:50 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-11-10 13:42:50 +0100 |
| commit | 01862f6b40c0f8fbc0123f1ac5140a406c268251 (patch) | |
| tree | f2523cf1572a8044114fc1a45030c447c73049df /labb4/GameState.cpp | |
| parent | b8da24cd224f9c4d793bb4bb9809b6b517f0ee38 (diff) | |
| download | tddd86-01862f6b40c0f8fbc0123f1ac5140a406c268251.tar.gz | |
destructor and copy assignment operator
Diffstat (limited to 'labb4/GameState.cpp')
| -rw-r--r-- | labb4/GameState.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/labb4/GameState.cpp b/labb4/GameState.cpp index 6de11dd..47842a1 100644 --- a/labb4/GameState.cpp +++ b/labb4/GameState.cpp @@ -27,6 +27,28 @@ GameState::GameState(const GameState &other) { hero = other.hero; } +/* +*/ +GameState::~GameState() { + for (const auto &robot : robots) { + delete robot; + } + robots.clear(); +} + +GameState &GameState::operator=(const GameState &other) { + for (const auto &robot : robots) { + delete robot; + } + robots.clear(); + for (const auto &robot : other.robots) { + robots.push_back(robot->clone()); + } + hero = other.hero; + + return *this; +} + void GameState::draw(QGraphicsScene *scene) const { scene->clear(); for (int i = 0; i < robots.size(); i++) { |
