From e81653bf5dbc0be629f9e5c02e81b7ea407e33b6 Mon Sep 17 00:00:00 2001 From: kinou-p Date: Sun, 19 Jun 2022 16:11:22 +0200 Subject: [PATCH] end ex03 --- cpp01/ex03/HumanA.cpp | 7 +++---- cpp01/ex03/HumanA.hpp | 6 +++--- cpp01/ex03/HumanB.cpp | 17 ++++++----------- cpp01/ex03/HumanB.hpp | 8 ++++---- cpp01/ex03/Weapon.cpp | 24 +++++++++++++++++++----- cpp01/ex03/Weapon.hpp | 12 +++++++----- 6 files changed, 42 insertions(+), 32 deletions(-) diff --git a/cpp01/ex03/HumanA.cpp b/cpp01/ex03/HumanA.cpp index 644cb1a..baa6e09 100644 --- a/cpp01/ex03/HumanA.cpp +++ b/cpp01/ex03/HumanA.cpp @@ -6,16 +6,15 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/10 21:20:34 by apommier #+# #+# */ -/* Updated: 2022/06/16 23:41:51 by apommier ### ########.fr */ +/* Updated: 2022/06/19 12:36:43 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ #include "HumanA.hpp" -HumanA::HumanA(const std::string name, Weapon Weapon) +HumanA::HumanA(const std::string name, Weapon &Weapon): _Weapon(Weapon) { this->_name = name; - this->_Weapon = &Weapon.getType(); } HumanA::~HumanA(void) @@ -25,5 +24,5 @@ HumanA::~HumanA(void) void HumanA::attack(void) { - std::cout << this->_name << " attacks with their " << this->_Weapon << std::endl; + std::cout << this->_name << " attacks with their " << this->_Weapon.getType() << std::endl; } \ No newline at end of file diff --git a/cpp01/ex03/HumanA.hpp b/cpp01/ex03/HumanA.hpp index b6e4b63..3bae7f9 100644 --- a/cpp01/ex03/HumanA.hpp +++ b/cpp01/ex03/HumanA.hpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/10 21:20:32 by apommier #+# #+# */ -/* Updated: 2022/06/16 23:39:42 by apommier ### ########.fr */ +/* Updated: 2022/06/19 12:22:11 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,14 +20,14 @@ class HumanA { public: - HumanA(const std::string name, Weapon Weapon); + HumanA(const std::string name, Weapon &Weapon); ~HumanA(void); void attack(void); private: std::string _name; - std::string *_Weapon; + Weapon &_Weapon; }; diff --git a/cpp01/ex03/HumanB.cpp b/cpp01/ex03/HumanB.cpp index 7ada8eb..e9b7572 100644 --- a/cpp01/ex03/HumanB.cpp +++ b/cpp01/ex03/HumanB.cpp @@ -6,36 +6,31 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/10 21:25:58 by apommier #+# #+# */ -/* Updated: 2022/06/16 23:42:41 by apommier ### ########.fr */ +/* Updated: 2022/06/19 16:08:30 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ #include "HumanB.hpp" - -HumanB::HumanB(const std::string name) +HumanB::HumanB(std::string name) : _name(name), _Weapon(NULL) { - this->_name = name; - //this->_Weapon = NULL; } HumanB::HumanB(const std::string name, Weapon Weapon) { this->_name = name; - this->_Weapon = Weapon.getType(); + this->_Weapon = &Weapon; } HumanB::~HumanB(void) { - } -void HumanB::setWeapon(Weapon Weapon) -{ - this->_Weapon = Weapon.getType(); +void HumanB::setWeapon(Weapon &newWeapon) { + _Weapon = &newWeapon; } void HumanB::attack(void) const { - std::cout << this->_name << " attacks with their " << this->_Weapon << std::endl; + std::cout << this->_name << " attacks with their " << this->_Weapon->getType() << std::endl; } \ No newline at end of file diff --git a/cpp01/ex03/HumanB.hpp b/cpp01/ex03/HumanB.hpp index ecb59e0..e993285 100644 --- a/cpp01/ex03/HumanB.hpp +++ b/cpp01/ex03/HumanB.hpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/10 21:23:58 by apommier #+# #+# */ -/* Updated: 2022/06/16 23:32:27 by apommier ### ########.fr */ +/* Updated: 2022/06/19 16:07:36 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,16 +19,16 @@ class HumanB { public: + HumanB(std::string name); HumanB(const std::string name, Weapon Weapon); - HumanB (const std::string name); ~HumanB(void); void attack(void) const; - void setWeapon(Weapon Weapon); + void setWeapon(Weapon &newWeapon); private: std::string _name; - std::string &_Weapon; + Weapon *_Weapon; }; diff --git a/cpp01/ex03/Weapon.cpp b/cpp01/ex03/Weapon.cpp index ca169dc..90a8901 100644 --- a/cpp01/ex03/Weapon.cpp +++ b/cpp01/ex03/Weapon.cpp @@ -6,27 +6,41 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/10 21:13:13 by apommier #+# #+# */ -/* Updated: 2022/06/16 22:25:56 by apommier ### ########.fr */ +/* Updated: 2022/06/19 15:54:48 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ #include "Weapon.hpp" -Weapon::Weapon(std::string name): _type(name) { +Weapon::Weapon() : _type("words"){ + return; +} +Weapon::Weapon(std::string type) : _type(type){ + return; +} + +Weapon::~Weapon() { + return; +} +/*Weapon::Weapon(std::string name): _type(name) { } Weapon::~Weapon() { -} +}*/ -const std::string &getType(void) + const std::string& Weapon::getType(void) const { return (this->_type); } -void setType(const std::string &type) +/*void Weapon::setType(const std::string type) { this->_type = type; +}*/ + +void Weapon::setType(std::string newType) { + _type = newType; } \ No newline at end of file diff --git a/cpp01/ex03/Weapon.hpp b/cpp01/ex03/Weapon.hpp index 0b3a888..ab616f1 100644 --- a/cpp01/ex03/Weapon.hpp +++ b/cpp01/ex03/Weapon.hpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/10 19:43:13 by apommier #+# #+# */ -/* Updated: 2022/06/16 23:39:20 by apommier ### ########.fr */ +/* Updated: 2022/06/19 15:55:10 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,10 +21,12 @@ class Weapon { public: - Weapon(std::string str); - ~Weapon(void); - std::string& getType(void); - void setType(const std::string type); + Weapon(); + Weapon(std::string type); + ~Weapon(); + const std::string& getType( void ) const; + //void setType(const std::string type); + void setType(std::string newType); private: