d04 ex02 change pour pouvoir effectuer le test de erlazo
This commit is contained in:
@@ -17,12 +17,19 @@ Cat::Cat() {
|
||||
return;
|
||||
}
|
||||
Cat::Cat( Brain * brain ) {
|
||||
std::cout << COPLIEN_COLOR "Cat parameters constructor" RESET "\n";
|
||||
std::cout << COPLIEN_COLOR "Cat parameters brain constructor" RESET "\n";
|
||||
type = "cat";
|
||||
_brain = new Brain();
|
||||
*_brain = *brain;
|
||||
return;
|
||||
}
|
||||
Cat::Cat( std::string ideas ) {
|
||||
std::cout << COPLIEN_COLOR "Cat parameters ideas constructor" RESET "\n";
|
||||
type = "cat";
|
||||
_brain = new Brain();
|
||||
_brain->putIdeas(ideas);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* error: base class ‘class Animal’ should be explicitly initialized in the copy constructor [-Werror=extra]
|
||||
@@ -52,9 +59,19 @@ Cat::~Cat() {
|
||||
*********************************************/
|
||||
|
||||
Cat & Cat::operator=( Cat const & rhs ) {
|
||||
std::cout << COPLIEN_COLOR "Cat assignator" RESET "\n";
|
||||
Animal::operator=(rhs);
|
||||
*_brain = *rhs._brain;
|
||||
std::cout << COPLIEN_COLOR "Cat assignator" RESET "\n";
|
||||
if (this != &rhs)
|
||||
*_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
|
||||
Cat & Cat::operator=( Animal const & rhs ) {
|
||||
Animal::operator=(rhs);
|
||||
std::cout << COPLIEN_COLOR "Cat (Animal) assignator" RESET "\n";
|
||||
if (this != &rhs)
|
||||
*_brain = *(rhs.getBrain());
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -71,3 +88,6 @@ void Cat::printBrain() const {
|
||||
void Cat::printBrain(int pos) const {
|
||||
_brain->printIdea(pos);
|
||||
}
|
||||
|
||||
Brain * Cat::getBrain() const { return _brain; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user