summaryrefslogtreecommitdiffstats
path: root/labb4/test-rule-of-three/main.cpp
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-11-10 13:42:50 +0100
committerGustav Sörnäs <gustav@sornas.net>2020-11-10 13:42:50 +0100
commit01862f6b40c0f8fbc0123f1ac5140a406c268251 (patch)
treef2523cf1572a8044114fc1a45030c447c73049df /labb4/test-rule-of-three/main.cpp
parentb8da24cd224f9c4d793bb4bb9809b6b517f0ee38 (diff)
downloadtddd86-01862f6b40c0f8fbc0123f1ac5140a406c268251.tar.gz
destructor and copy assignment operator
Diffstat (limited to 'labb4/test-rule-of-three/main.cpp')
-rw-r--r--labb4/test-rule-of-three/main.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/labb4/test-rule-of-three/main.cpp b/labb4/test-rule-of-three/main.cpp
index ccef31a..6747169 100644
--- a/labb4/test-rule-of-three/main.cpp
+++ b/labb4/test-rule-of-three/main.cpp
@@ -35,14 +35,17 @@ GameState::GameState(const GameState &other) {
GameState &GameState::operator=(const GameState &other) {
std::cout << "=" << std::endl;
- thing = other.thing;
+ delete thing;
+ thing = other.thing->clone();
return *this;
}
GameState::~GameState() {
std::cout << "d gamestate" << std::endl;
- delete thing;
- thing = nullptr;
+ if (thing) {
+ delete thing;
+ thing = nullptr;
+ }
}
void GameState::switchThing() {