ex01 finished

This commit is contained in:
2025-11-10 20:46:53 +01:00
parent b4b5a9b592
commit 783d649289
7 changed files with 98 additions and 29 deletions

View File

@@ -25,9 +25,10 @@ Cat::~Cat()
delete (this->brain);
}
Cat::Cat(const Cat &other)
Cat::Cat(const Cat &other) : Animal(other)
{
std::cout << "Cat copied" << std::endl;
this->brain = NULL;
*this = other;
}
@@ -35,7 +36,12 @@ Cat& Cat::operator=(const Cat &other)
{
std::cout << "Cat copy assignment called" << std::endl;
if (this != &other)
this->type = other.type;
{
Animal::operator=(other);
if (this->brain)
delete (this->brain);
this->brain = new Brain(*other.brain);
}
return (*this);
}

View File

@@ -30,6 +30,8 @@ class Cat : public Animal
Cat& operator=(const Cat &other);
void makeSound() const;
Brain* getBrain() const { return brain; }
};
#endif