From c1840c4501f774afcf118c21d6003088fedd17ef Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Fri, 25 Oct 2024 16:49:18 +0200 Subject: [PATCH] Make main not throw away temp objects on heap The subject says that learnMateria "Copies the Materia passed as a parameter and store it in memory so it can be cloned later." From that I get that learnMateria makes a copy of the Materia passed meaning we cant use "new AMateria()" to learn it, as we have no handle to that object to delete it. --- ex03/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ex03/main.cpp b/ex03/main.cpp index 3518a3b..bffc688 100644 --- a/ex03/main.cpp +++ b/ex03/main.cpp @@ -13,11 +13,11 @@ int main() ICharacter* bob = new Character("bob"); AMateria* tmp; - src->learnMateria(new Ice()); - src->learnMateria(new Cure()); tmp = src->createMateria("ice"); + src->learnMateria(tmp); me->equip(tmp); tmp = src->createMateria("cure"); + src->learnMateria(tmp); me->equip(tmp); me->use(0, *bob); me->use(1, *bob); -- 2.30.2