ex01 finished
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ class Cat : public Animal
|
||||
Cat& operator=(const Cat &other);
|
||||
|
||||
void makeSound() const;
|
||||
|
||||
Brain* getBrain() const { return brain; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user