d01 ex03 ref and ptr
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ public:
|
||||
Weapon( std::string type );
|
||||
~Weapon();
|
||||
|
||||
std::string getType();
|
||||
std::string getType() const;
|
||||
void setType( std::string type );
|
||||
|
||||
private:
|
||||
|
||||
BIN
d01/ex03/war
BIN
d01/ex03/war
Binary file not shown.
Reference in New Issue
Block a user