transform d03 ex01 assignation function in case of two constructors, tests of assignation and copy operation not successful
This commit is contained in:
@@ -12,7 +12,7 @@ int ClapTrap::_totalNumber = 0;
|
||||
|
||||
ClapTrap::ClapTrap( void ) {
|
||||
|
||||
std::cout << "claptrap created without name\n";
|
||||
std::cout << "claptrap default creation without name\n";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ ClapTrap::~ClapTrap( void ) {
|
||||
*/
|
||||
|
||||
ClapTrap::ClapTrap( ClapTrap const & src ) {
|
||||
std::cout << _class << " " << _name << " copied\n";
|
||||
*this = src;
|
||||
std::cout << _class << " " << _name << " copied\n";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,9 @@ ClapTrap & ClapTrap::operator=( ClapTrap const & 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();
|
||||
}
|
||||
|
||||
std::cout << _class << " " << _name << " assigned\n";
|
||||
@@ -65,9 +68,9 @@ ClapTrap::ClapTrap( std::string name ) : _name(name) {
|
||||
_hit = 10;
|
||||
_energy = 10;
|
||||
_attack = 1;
|
||||
_number = _getNumber();
|
||||
_number = getNumber();
|
||||
|
||||
std::cout << _class << " " << _name << " created with number " << _number << "\n";
|
||||
std::cout << _class << " " << _name << " named creation with number " << _number << "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -76,10 +79,11 @@ ClapTrap::ClapTrap( std::string name ) : _name(name) {
|
||||
*/
|
||||
|
||||
std::string ClapTrap::getName() const {return _name;}
|
||||
std::string ClapTrap::getClass() const {return _class;}
|
||||
int ClapTrap::getHit() const {return _hit;}
|
||||
int ClapTrap::getEnergy() const {return _energy;}
|
||||
int ClapTrap::getAttack() const {return _attack;}
|
||||
int ClapTrap::_getNumber() {return ClapTrap::_totalNumber;}
|
||||
int ClapTrap::getNumber() const {return ClapTrap::_totalNumber;}
|
||||
void ClapTrap::_increaseNumber() {ClapTrap::_totalNumber++;}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user