-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCat.cpp
More file actions
44 lines (38 loc) · 728 Bytes
/
Copy pathCat.cpp
File metadata and controls
44 lines (38 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "Cat.hpp"
#include <iostream>
Cat::Cat() : Animal()
{
_type = "Cat";
_brain = new Brain();
std::cout << "Cat constructed" << std::endl;
}
Cat::Cat(const Cat& other) : Animal(other)
{
_brain = new Brain(*other._brain);
std::cout << "Cat copy constructed" << std::endl;
}
Cat& Cat::operator=(const Cat& other)
{
std::cout << "Cat assignment operator called" << std::endl;
if (this != &other)
{
Animal::operator=(other);
if (_brain)
delete _brain;
_brain = new Brain(*other._brain);
}
return *this;
}
Cat::~Cat()
{
delete _brain;
std::cout << "Cat destructed" << std::endl;
}
void Cat::makeSound() const
{
std::cout << "Miaou !" << std::endl;
}
Brain* Cat::getBrain() const
{
return _brain;
}