diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-11-13 14:43:17 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-11-13 14:43:17 +0100 |
| commit | 4c30e98f4a4018a25d3a9f3ee790d589be803cb0 (patch) | |
| tree | 655a4bd52a7a6633a32782eab935fb01a47040e9 /cpp04/ex02/Squad.cpp | |
| parent | b8e39b947890e74d82530e25ad9d02668aae1f0c (diff) | |
| download | piscine_cpp-4c30e98f4a4018a25d3a9f3ee790d589be803cb0.tar.gz piscine_cpp-4c30e98f4a4018a25d3a9f3ee790d589be803cb0.tar.bz2 piscine_cpp-4c30e98f4a4018a25d3a9f3ee790d589be803cb0.zip | |
Added main for cpp04/ex01 and cpp04/ex02, Fixed cpp04/03 MateriaSource
Diffstat (limited to 'cpp04/ex02/Squad.cpp')
| -rw-r--r-- | cpp04/ex02/Squad.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/cpp04/ex02/Squad.cpp b/cpp04/ex02/Squad.cpp index d1d988f..1cc59f0 100644 --- a/cpp04/ex02/Squad.cpp +++ b/cpp04/ex02/Squad.cpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 15:08:35 by charles #+# #+# */ -/* Updated: 2020/11/12 15:38:55 by cacharle ### ########.fr */ +/* Updated: 2020/11/13 12:13:57 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,12 +14,12 @@ Squad::Squad() : m_units(new ISpaceMarine*[0]), m_size(0) {} -Squad::Squad(Squad const& other) { *this = other; } +Squad::Squad(Squad const& other) : m_units(NULL), m_size(0) { *this = other; } Squad& Squad::operator=(Squad const& other) { destroyUnits(); - m_size = other.m_size; + m_size = other.m_size; m_units = new ISpaceMarine*[m_size]; for (int i = 0; i < m_size; i++) m_units[i] = other.m_units[i]->clone(); @@ -57,6 +57,8 @@ int Squad::push(ISpaceMarine* spaceMarine) void Squad::destroyUnits() { + if (m_units == NULL) + return; for (int i = 0; i < m_size; i++) delete m_units[i]; delete [] m_units; |
