aboutsummaryrefslogtreecommitdiff
path: root/cpp04/ex03
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-12-11 12:11:50 +0100
committerCharles Cabergs <me@cacharle.xyz>2020-12-11 12:11:50 +0100
commitc10aa969c60cedef893146307fa319250901465a (patch)
treee3dfa785191047ee8e2ed533f963fe7c5cd7aacf /cpp04/ex03
parent6169d697a5be59426d034b878bffc848de49491d (diff)
downloadpiscine_cpp-c10aa969c60cedef893146307fa319250901465a.tar.gz
piscine_cpp-c10aa969c60cedef893146307fa319250901465a.tar.bz2
piscine_cpp-c10aa969c60cedef893146307fa319250901465a.zip
Fixing cpp04 according to correction
Diffstat (limited to 'cpp04/ex03')
-rw-r--r--cpp04/ex03/Character.cpp3
-rw-r--r--cpp04/ex03/Cure.hpp4
-rw-r--r--cpp04/ex03/Ice.hpp4
-rw-r--r--cpp04/ex03/main.cpp19
4 files changed, 18 insertions, 12 deletions
diff --git a/cpp04/ex03/Character.cpp b/cpp04/ex03/Character.cpp
index 57fcfeb..42e07da 100644
--- a/cpp04/ex03/Character.cpp
+++ b/cpp04/ex03/Character.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 16:45:54 by charles #+# #+# */
-/* Updated: 2020/11/17 08:30:21 by cacharle ### ########.fr */
+/* Updated: 2020/12/11 12:08:56 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -44,7 +44,6 @@ void Character::unequip(int idx)
{
if (idx < 0 || idx >= m_inventory_size)
return;
- delete m_inventory[idx];
for (int i = idx; i < m_inventory_size - 1; i++)
m_inventory[i] = m_inventory[i + 1];
m_inventory_size--;
diff --git a/cpp04/ex03/Cure.hpp b/cpp04/ex03/Cure.hpp
index 71647ff..9b45020 100644
--- a/cpp04/ex03/Cure.hpp
+++ b/cpp04/ex03/Cure.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 17:37:11 by charles #+# #+# */
-/* Updated: 2020/11/13 14:09:18 by cacharle ### ########.fr */
+/* Updated: 2020/12/11 11:41:11 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,7 +22,7 @@ public:
Cure();
Cure(Cure const& other);
Cure& operator=(Cure const& other);
- ~Cure();
+ virtual ~Cure();
virtual AMateria* clone() const;
virtual void use(ICharacter& target);
diff --git a/cpp04/ex03/Ice.hpp b/cpp04/ex03/Ice.hpp
index 41f07de..637f440 100644
--- a/cpp04/ex03/Ice.hpp
+++ b/cpp04/ex03/Ice.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 16:31:34 by charles #+# #+# */
-/* Updated: 2020/11/13 14:09:24 by cacharle ### ########.fr */
+/* Updated: 2020/12/11 11:41:02 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,7 +22,7 @@ public:
Ice();
Ice(Ice const& other);
Ice& operator=(Ice const& other);
- ~Ice();
+ virtual ~Ice();
virtual AMateria* clone() const;
virtual void use(ICharacter& target);
diff --git a/cpp04/ex03/main.cpp b/cpp04/ex03/main.cpp
index bede834..a45b990 100644
--- a/cpp04/ex03/main.cpp
+++ b/cpp04/ex03/main.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 17:58:01 by charles #+# #+# */
-/* Updated: 2020/11/17 08:33:22 by cacharle ### ########.fr */
+/* Updated: 2020/12/11 12:08:44 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -135,12 +135,16 @@ int main()
std::cout << "Name: " << c3.getName() << std::endl;
std::cout << "################## EQUIP/USE" << std::endl;
- c.equip(new Ice());
- c.equip(new Cure());
+ AMateria *tmp0 = new Ice();
+ AMateria *tmp1 = new Cure();
+ AMateria *tmp2 = new Cure();
+ AMateria *tmp3 = new Ice();
+ c.equip(tmp0);
+ c.equip(tmp1);
c.use(0, ch);
c.use(1, ch);
- c.equip(new Cure());
- c.equip(new Ice());
+ c.equip(tmp2);
+ c.equip(tmp3);
c.use(2, ch);
c.use(3, ch);
c.use(-1, ch);
@@ -165,6 +169,10 @@ int main()
c.use(0, ch);
c.equip(NULL);
c.use(1, ch);
+ delete tmp0;
+ delete tmp1;
+ delete tmp2;
+ delete tmp3;
std::cout << "################## DEEP COPY" << std::endl;
c.equip(new Ice());
@@ -191,7 +199,6 @@ int main()
ic->use(2, ch);
ic->equip(new Ice());
ic->use(3, ch);
- ic->unequip(1);
ic->use(1, ch);
delete ic;
}