d01 ex03 ref and ptr
This commit is contained in:
@@ -1,19 +1,19 @@
|
|||||||
#include "HumanA.hpp"
|
#include "HumanA.hpp"
|
||||||
|
|
||||||
HumanA::HumanA( std::string name, Weapon weapon ) {
|
HumanA::HumanA( std::string name, Weapon &weapon ) : _weapon( weapon ) {
|
||||||
|
|
||||||
this->_name = name;
|
this->_name = name;
|
||||||
this->_weapon = &weapon;
|
// this->_weapon = weapon;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
HumanA::~HumanA() {return;}
|
HumanA::~HumanA() {return;}
|
||||||
|
|
||||||
void HumanA::attack( void ) {
|
void HumanA::attack( void ) const {
|
||||||
|
|
||||||
std::cout << this->_name << " attacks with their ";
|
std::cout << this->_name << " attacks with their ";
|
||||||
std::cout << this->_weapon->getType() << std::endl;
|
std::cout << this->_weapon.getType() << std::endl;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -9,15 +9,15 @@ class HumanA {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
HumanA( std::string name, Weapon weapon );
|
HumanA( std::string name, Weapon &weapon );
|
||||||
~HumanA();
|
~HumanA();
|
||||||
|
|
||||||
void attack( void );
|
void attack( void ) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string _name;
|
std::string _name;
|
||||||
Weapon * _weapon;
|
Weapon & _weapon;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ HumanB::HumanB( std::string name ) {
|
|||||||
}
|
}
|
||||||
HumanB::~HumanB() {}
|
HumanB::~HumanB() {}
|
||||||
|
|
||||||
void HumanB::setWeapon( Weapon weapon ) {
|
void HumanB::setWeapon( Weapon &weapon ) {
|
||||||
|
|
||||||
this->_weapon = &weapon;
|
this->_weapon = &weapon;
|
||||||
|
|
||||||
@@ -15,7 +15,8 @@ void HumanB::setWeapon( Weapon weapon ) {
|
|||||||
|
|
||||||
void HumanB::attack( void ) {
|
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,7 +13,7 @@ public:
|
|||||||
~HumanB();
|
~HumanB();
|
||||||
|
|
||||||
void attack( void );
|
void attack( void );
|
||||||
void setWeapon( Weapon weapon );
|
void setWeapon( Weapon &weapon );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -3,21 +3,19 @@
|
|||||||
Weapon::Weapon( std::string type ) {
|
Weapon::Weapon( std::string type ) {
|
||||||
|
|
||||||
this->_type = type;
|
this->_type = type;
|
||||||
std::cout << "weapon constructor received : " << this->_type << std::endl;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
Weapon::~Weapon() {}
|
Weapon::~Weapon() {}
|
||||||
|
|
||||||
std::string Weapon::getType( void ) {
|
std::string Weapon::getType( void ) const {
|
||||||
|
|
||||||
return this->_type;
|
return this->_type;
|
||||||
std::cout << "weapon getType() return : " << this->_type << std::endl;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Weapon::setType( std::string type ) {
|
void Weapon::setType( std::string type ) {
|
||||||
|
|
||||||
this->_type = 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 type );
|
||||||
~Weapon();
|
~Weapon();
|
||||||
|
|
||||||
std::string getType();
|
std::string getType() const;
|
||||||
void setType( std::string type );
|
void setType( std::string type );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
BIN
d01/ex03/war
BIN
d01/ex03/war
Binary file not shown.
Reference in New Issue
Block a user