aboutsummaryrefslogtreecommitdiff
path: root/cpp01/ex03/ZombieHorde.cpp
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-11-09 12:58:53 +0100
committerCharles Cabergs <me@cacharle.xyz>2020-11-09 12:58:53 +0100
commit631a8d7b6c214da48f7748e78fc8c308960414fb (patch)
treef68b1b79c9092ee14f78e93b8d5b157c8313c51a /cpp01/ex03/ZombieHorde.cpp
parent0458a2f2fb93abcbf5f400e5eb1121a24e752ae1 (diff)
downloadpiscine_cpp-631a8d7b6c214da48f7748e78fc8c308960414fb.tar.gz
piscine_cpp-631a8d7b6c214da48f7748e78fc8c308960414fb.tar.bz2
piscine_cpp-631a8d7b6c214da48f7748e78fc8c308960414fb.zip
Fixing cpp01/03 single allocation for zombies in horde
Diffstat (limited to 'cpp01/ex03/ZombieHorde.cpp')
-rw-r--r--cpp01/ex03/ZombieHorde.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/cpp01/ex03/ZombieHorde.cpp b/cpp01/ex03/ZombieHorde.cpp
index 0492fb3..c0eb974 100644
--- a/cpp01/ex03/ZombieHorde.cpp
+++ b/cpp01/ex03/ZombieHorde.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:52:11 by charles #+# #+# */
-/* Updated: 2020/11/09 10:57:08 by cacharle ### ########.fr */
+/* Updated: 2020/11/09 12:58:23 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -39,17 +39,18 @@ ZombieHorde::ZombieHorde(int n)
"earth",
"wind"
};
- m_horde = new Zombie*[m_size];
+ m_horde = new Zombie[m_size];
for (size_t i = 0; i < m_size; i++)
- m_horde[i] = new Zombie(name_pool[rand() % 10], type_pool[rand() % 4]);
+ {
+ m_horde[i].setName(name_pool[rand() % 10]);
+ m_horde[i].setType(type_pool[rand() % 4]);
+ }
}
ZombieHorde::~ZombieHorde()
{
if (m_horde == NULL)
return;
- for (size_t i = 0; i < m_size; i++)
- delete m_horde[i];
delete [] m_horde;
}
@@ -58,5 +59,5 @@ void ZombieHorde::announce()
if (m_horde == NULL)
return;
for (size_t i = 0; i < m_size; i++)
- m_horde[i]->announce();
+ m_horde[i].announce();
}