d04 ex02 change pour pouvoir effectuer le test de erlazo

This commit is contained in:
hugogogo
2022-03-12 16:21:56 +01:00
parent 329e38b84b
commit 96e78e34a1
11 changed files with 138 additions and 16 deletions

View File

@@ -49,9 +49,18 @@ Dog::~Dog() {
Dog & Dog::operator=( Dog const & rhs ) {
Animal::operator=(rhs);
_brain = new Brain();
std::cout << COPLIEN_COLOR "Dog assignator" RESET "\n";
if (this != &rhs)
_brain = rhs._brain;
*_brain = *(rhs.getBrain());
return *this;
}
// need of a second overload in case "Animal cat" = "Animal cat";
// https://stackoverflow.com/questions/68248198/why-my-virtual-assignment-operator-not-doing-as-intended
Dog & Dog::operator=( Animal const & rhs ) {
Animal::operator=(rhs);
std::cout << COPLIEN_COLOR "Cat (Animal) assignator" RESET "\n";
if (this != &rhs)
*_brain = *(rhs.getBrain());
return *this;
}
@@ -63,3 +72,4 @@ void Dog::makeSound() const {
std::cout << "*woof*\n";
}
Brain * Dog::getBrain() const { return _brain; }