From: Lukas Jiriste Date: Fri, 25 Oct 2024 14:49:18 +0000 (+0200) Subject: Make main not throw away temp objects on heap X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=c1840c4501f774afcf118c21d6003088fedd17ef;p=42%2FCPP_Module_04 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. --- 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);