recration of ex03

This commit is contained in:
2023-07-17 21:35:02 +02:00
parent 98ece4839e
commit 3ef324e5e1
9 changed files with 142 additions and 85 deletions

View File

@ -1,29 +1,43 @@
#include "HumanB.hpp"
#include "Weapon.hpp"
#include <cstddef>
#include <string>
#include <iostream>
HumanB::HumanB(std::string name)
#include <iostream>
#include <string>
HumanB::HumanB(const std::string& name)
{
this->weapon = NULL;
this->name = name;
this->_name = name;
}
HumanB::HumanB()
{
std::cout << "HumanB()" << std::endl;
}
HumanB::HumanB(const HumanB& src)
{
*this = src;
}
HumanB::~HumanB()
{}
void HumanB::attack()
{
if (this->weapon == NULL)
{
std::cerr << this->name << " can't attack without weapon" << std::endl;
return;
}
std::cout << this->name << " attacks with their " << this->weapon->getType() << std::endl;
std::cout << "~HumanB()" << std::endl;
}
void HumanB::setWeapon(Weapon& new_weapon)
HumanB& HumanB::operator=(const HumanB& src)
{
this->weapon = &new_weapon;
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;
}
void HumanB::setWeapon(const Weapon &weapon)
{
this->_weapon = weapon;
}