d03 ex01 pas encore tout au point sur les constructors

This commit is contained in:
Hugo LAMY
2022-02-21 17:01:52 +01:00
parent 7a9435b869
commit 985d90bb8c
5 changed files with 95 additions and 99 deletions

View File

@@ -1,80 +1,68 @@
#include "ScavTrap.hpp"
/*
* assign values for default or secondary constructors
*/
void ScavTrap::assignValues( ScavTrap & src ) {
src._class = "ScavTrap";
src._hit = 100;
src._energy = 50;
src._attack = 20;
}
/*
* default constructor
*/
ScavTrap::ScavTrap() {
assignValues(*this);
std::cout << _class << " " << " default construction with number " << _number << "\n";
return;
}
/*
* parameters constructor
*/
/*********************************************
* CONSTRUCTORS
*********************************************/
ScavTrap::ScavTrap( std::string name ) : ClapTrap(name) {
assignValues(*this);
std::cout << _class << " " << _name << " named creation with number " << _number << "\n";
_class = _dClass;
_hit = _dHit;
_energy = _dEnergy;
_attack = _dAttack;
std::cout << _class << " " << _name << " nb:" << _number << " created\n";
return;
}
/*
* destructor
*/
ScavTrap::ScavTrap( ScavTrap const & src ) : ClapTrap() {
_class = _dClass;
*this = src;
std::cout << _class << " " << _name << " nb:" << _number << " copied from " << src._class << "-" << src._name << "-" << src._number << "\n";
return;
}
/*********************************************
* DESTRUCTORS
*********************************************/
ScavTrap::~ScavTrap( void ) {
std::cout << _class << " " << _name << " destructed\n";
std::cout << _class << " " << _name << " nb:" << _number << " destructed\n";
return;
}
/*
* special capacity
*/
void ScavTrap::guardGate() {
std::cout << _class << " " << _name << " entered special mode Gate Keeper\n";
}
/*
* copy constructor
*/
ScavTrap::ScavTrap( ScavTrap const & src ) {
*this = src;
std::cout << _class << " " << _name << " copied\n";
return;
}
/*
* assignement operator
*/
/*********************************************
* OPERATORS
*********************************************/
ScavTrap & ScavTrap::operator=( ScavTrap const & rhs ) {
if ( this != &rhs )
{
this->_hit = rhs.getHit();
this->_energy = rhs.getEnergy();
this->_attack = rhs.getAttack();
this->_class = rhs.getClass();
this->_name = rhs.getName();
this->_number = rhs.getNumber();
_hit = rhs.getHit();
_energy = rhs.getEnergy();
_attack = rhs.getAttack();
_name = rhs.getName();
}
std::cout << _class << " " << _name << " assigned\n";
std::cout << _class << " " << _name << " nb:" << _number << " assigned\n";
return *this;
}
/*********************************************
* PUBLIC MEMBER FUNCTIONS
*********************************************/
void ScavTrap::guardGate() {
std::cout << _class << " " << _name << " entered special mode Gate Keeper\n";
}
/*********************************************
* STATICS
*********************************************/
std::string const ScavTrap::_dName = "robot";
std::string const ScavTrap::_dClass = "ScavTrap";
int const ScavTrap::_dHit = 100;
int const ScavTrap::_dEnergy = 50;
int const ScavTrap::_dAttack = 20;