fix: ex03

This commit is contained in:
2023-07-19 23:26:04 +02:00
parent eb2b035b75
commit efa91c0cb5
7 changed files with 20 additions and 48 deletions

View File

@ -4,18 +4,10 @@
#include <string>
HumanB::HumanB(const std::string& name)
{
this->_name = name;
}
HumanB::HumanB()
{
std::cout << "HumanB()" << std::endl;
}
HumanB::HumanB(const HumanB& src)
{
*this = src;
this->_name = name;
this->_weapon = NULL;
}
HumanB::~HumanB()
@ -23,21 +15,19 @@ HumanB::~HumanB()
std::cout << "~HumanB()" << std::endl;
}
HumanB& HumanB::operator=(const HumanB& src)
{
this->_weapon = src._weapon;
this->_name = src._name;
return *this;
}
void HumanB::attack()
{
std::cout << this->_name << " attacks with their " << this->_weapon.getType() << std::endl;
std::cout << this->_name << " attacks with their ";
if (this->_weapon == NULL)
std::cout << "hands";
else
std::cout << this->_weapon->getType();
std::cout << std::endl;
}
void HumanB::setWeapon(const Weapon &weapon)
{
this->_weapon = weapon;
this->_weapon = &weapon;
}