From 841697f039dc5670f53ec6597ef6f639eeebcb5a Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 20 Sep 2022 14:45:17 +0200 Subject: fix memory leak --- week-3/Persoon.cpp | 5 +++++ week-3/Persoon.h | 1 + 2 files changed, 6 insertions(+) diff --git a/week-3/Persoon.cpp b/week-3/Persoon.cpp index f66e1f9..d58028c 100644 --- a/week-3/Persoon.cpp +++ b/week-3/Persoon.cpp @@ -4,7 +4,12 @@ Persoon::Persoon() { _beroep = NULL; } +Persoon::~Persoon() { + delete _beroep; +} + void Persoon::setBeroep(IBeroep* beroep) { + delete _beroep; _beroep = beroep; } diff --git a/week-3/Persoon.h b/week-3/Persoon.h index 88c742d..32ff651 100644 --- a/week-3/Persoon.h +++ b/week-3/Persoon.h @@ -11,5 +11,6 @@ class Persoon { virtual void setBeroep(IBeroep* beroep); virtual std::string getBeroep(); Persoon(); + virtual ~Persoon(); }; -- cgit v1.2.3