ex01 finished
This commit is contained in:
@@ -25,9 +25,10 @@ Dog::~Dog()
|
||||
delete (this->brain);
|
||||
}
|
||||
|
||||
Dog::Dog(const Dog &other)
|
||||
Dog::Dog(const Dog &other) : Animal(other)
|
||||
{
|
||||
std::cout << "Dog copied" << std::endl;
|
||||
this->brain = NULL;
|
||||
*this = other;
|
||||
}
|
||||
|
||||
@@ -35,7 +36,12 @@ Dog& Dog::operator=(const Dog &other)
|
||||
{
|
||||
std::cout << "Dog 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ class Dog : public Animal
|
||||
|
||||
void makeSound() const;
|
||||
|
||||
Brain* getBrain() const { return brain; }
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user