aboutsummaryrefslogtreecommitdiff
path: root/cpp03/ex03
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-11-10 14:50:38 +0100
committerCharles Cabergs <me@cacharle.xyz>2020-11-10 15:06:45 +0100
commitaa40eb5dedd39263ff511de01d6833d24e33b736 (patch)
tree58031a52433ed08bb3347dd95ecb492b6b8c17ca /cpp03/ex03
parent18ca1fc67ccc7bf176287f7b2908a33a597ec67a (diff)
downloadpiscine_cpp-aa40eb5dedd39263ff511de01d6833d24e33b736.tar.gz
piscine_cpp-aa40eb5dedd39263ff511de01d6833d24e33b736.tar.bz2
piscine_cpp-aa40eb5dedd39263ff511de01d6833d24e33b736.zip
Changing operator= and const reference in Traps
Diffstat (limited to 'cpp03/ex03')
-rw-r--r--cpp03/ex03/NinjaTrap.cpp11
-rw-r--r--cpp03/ex03/NinjaTrap.hpp6
-rw-r--r--cpp03/ex03/ScavTrap.cpp3
3 files changed, 9 insertions, 11 deletions
diff --git a/cpp03/ex03/NinjaTrap.cpp b/cpp03/ex03/NinjaTrap.cpp
index 2a27eec..bdc3534 100644
--- a/cpp03/ex03/NinjaTrap.cpp
+++ b/cpp03/ex03/NinjaTrap.cpp
@@ -6,14 +6,13 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 17:33:00 by charles #+# #+# */
-/* Updated: 2020/04/13 17:47:20 by charles ### ########.fr */
+/* Updated: 2020/11/10 14:43:25 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "NinjaTrap.hpp"
-NinjaTrap::NinjaTrap():
- ClapTrap()
+NinjaTrap::NinjaTrap() : ClapTrap()
{
m_prefix = "NINJ4-TP ";
m_hitPoints = 60;
@@ -26,8 +25,7 @@ NinjaTrap::NinjaTrap():
std::cout << m_prefix << "New " << m_name << ": your gaming references suck" << std::endl;
}
-NinjaTrap::NinjaTrap(std::string name):
- ClapTrap(name)
+NinjaTrap::NinjaTrap(std::string const& name) : ClapTrap(name)
{
m_prefix = "NINJ4-TP ";
m_hitPoints = 60;
@@ -45,7 +43,7 @@ NinjaTrap::NinjaTrap(NinjaTrap const& other)
*this = other;
}
-void NinjaTrap::operator=(NinjaTrap const& other)
+NinjaTrap& NinjaTrap::operator=(NinjaTrap const& other)
{
m_hitPoints = other.m_hitPoints;
m_maxHitPoints = other.m_maxHitPoints;
@@ -55,6 +53,7 @@ void NinjaTrap::operator=(NinjaTrap const& other)
m_meleeAttackDamage = other.m_meleeAttackDamage;
m_rangedAttackDamage = other.m_rangedAttackDamage;
m_armorDamageReduction = other.m_armorDamageReduction;
+ return *this;
}
NinjaTrap::~NinjaTrap()
diff --git a/cpp03/ex03/NinjaTrap.hpp b/cpp03/ex03/NinjaTrap.hpp
index 217ae33..d075dba 100644
--- a/cpp03/ex03/NinjaTrap.hpp
+++ b/cpp03/ex03/NinjaTrap.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 17:31:24 by charles #+# #+# */
-/* Updated: 2020/04/13 17:45:16 by charles ### ########.fr */
+/* Updated: 2020/11/10 14:43:01 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,9 +21,9 @@ class NinjaTrap : public ClapTrap
{
public:
NinjaTrap();
- NinjaTrap(std::string name);
+ NinjaTrap(std::string const& name);
NinjaTrap(NinjaTrap const& other);
- void operator=(NinjaTrap const& other);
+ NinjaTrap& operator=(NinjaTrap const& other);
~NinjaTrap();
void ninjaShoebox(NinjaTrap const& target);
diff --git a/cpp03/ex03/ScavTrap.cpp b/cpp03/ex03/ScavTrap.cpp
index d310ab1..a1f4a17 100644
--- a/cpp03/ex03/ScavTrap.cpp
+++ b/cpp03/ex03/ScavTrap.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 14:15:03 by charles #+# #+# */
-/* Updated: 2020/04/13 15:46:56 by charles ### ########.fr */
+/* Updated: 2020/11/10 15:06:20 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -70,5 +70,4 @@ void ScavTrap::challengeNewcomer(std::string const& target)
std::cout << "SC4V-TP " << m_name
<< " challenge " << target
<< " to " << challenges[rand() % 5] << std::endl;
- m_energyPoints -= 25;
}