From 01862f6b40c0f8fbc0123f1ac5140a406c268251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 10 Nov 2020 13:42:50 +0100 Subject: destructor and copy assignment operator --- labb4/test-rule-of-three/main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'labb4/test-rule-of-three/main.cpp') 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() { -- cgit v1.2.1