diff --git a/d01/ex03/HumanA.cpp b/d01/ex03/HumanA.cpp index 3027f8f..ed7897c 100644 --- a/d01/ex03/HumanA.cpp +++ b/d01/ex03/HumanA.cpp @@ -1,19 +1,19 @@ #include "HumanA.hpp" -HumanA::HumanA( std::string name, Weapon weapon ) { +HumanA::HumanA( std::string name, Weapon &weapon ) : _weapon( weapon ) { this->_name = name; - this->_weapon = &weapon; +// this->_weapon = weapon; return; } HumanA::~HumanA() {return;} -void HumanA::attack( void ) { +void HumanA::attack( void ) const { std::cout << this->_name << " attacks with their "; - std::cout << this->_weapon->getType() << std::endl; + std::cout << this->_weapon.getType() << std::endl; return; diff --git a/d01/ex03/HumanA.hpp b/d01/ex03/HumanA.hpp index ece7e04..eb06038 100644 --- a/d01/ex03/HumanA.hpp +++ b/d01/ex03/HumanA.hpp @@ -9,15 +9,15 @@ class HumanA { public: - HumanA( std::string name, Weapon weapon ); + HumanA( std::string name, Weapon &weapon ); ~HumanA(); - void attack( void ); + void attack( void ) const; private: std::string _name; - Weapon * _weapon; + Weapon & _weapon; }; diff --git a/d01/ex03/HumanB.cpp b/d01/ex03/HumanB.cpp index de4a171..03c8a1f 100644 --- a/d01/ex03/HumanB.cpp +++ b/d01/ex03/HumanB.cpp @@ -7,7 +7,7 @@ HumanB::HumanB( std::string name ) { } HumanB::~HumanB() {} -void HumanB::setWeapon( Weapon weapon ) { +void HumanB::setWeapon( Weapon &weapon ) { this->_weapon = &weapon; @@ -15,7 +15,8 @@ void HumanB::setWeapon( Weapon weapon ) { void HumanB::attack( void ) { - std::cout << this->_name << " attacks with their " << this->_weapon->getType() << std::endl; + std::cout << this->_name << " attacks with their "; + std::cout << this->_weapon->getType() << std::endl; } diff --git a/d01/ex03/HumanB.hpp b/d01/ex03/HumanB.hpp index bc920b3..f8d5b0a 100644 --- a/d01/ex03/HumanB.hpp +++ b/d01/ex03/HumanB.hpp @@ -13,12 +13,12 @@ public: ~HumanB(); void attack( void ); - void setWeapon( Weapon weapon ); + void setWeapon( Weapon &weapon ); private: std::string _name; - Weapon * _weapon; + Weapon * _weapon; }; diff --git a/d01/ex03/Weapon.cpp b/d01/ex03/Weapon.cpp index 74f6132..c090ef6 100644 --- a/d01/ex03/Weapon.cpp +++ b/d01/ex03/Weapon.cpp @@ -3,21 +3,19 @@ Weapon::Weapon( std::string type ) { this->_type = type; - std::cout << "weapon constructor received : " << this->_type << std::endl; + return; } Weapon::~Weapon() {} -std::string Weapon::getType( void ) { +std::string Weapon::getType( void ) const { return this->_type; - std::cout << "weapon getType() return : " << this->_type << std::endl; } void Weapon::setType( std::string type ) { this->_type = type; - std::cout << "weapon setType() received : " << this->_type << std::endl; } diff --git a/d01/ex03/Weapon.hpp b/d01/ex03/Weapon.hpp index c81c6d2..859b55e 100644 --- a/d01/ex03/Weapon.hpp +++ b/d01/ex03/Weapon.hpp @@ -11,7 +11,7 @@ public: Weapon( std::string type ); ~Weapon(); - std::string getType(); + std::string getType() const; void setType( std::string type ); private: diff --git a/d01/ex03/war b/d01/ex03/war index 3aefd0b..ef9fa15 100755 Binary files a/d01/ex03/war and b/d01/ex03/war differ