cpp04/ex01/Dog.cpp

62 lines
1.2 KiB
C++

# include "Dog.hpp"
Dog::Dog() : Animal()
{
_type = "Dog";
_brain = new Brain();
std::cout << "Dog default constructor called\n";
}
Dog::Dog (std::string type) : Animal(type)
{
_type = type;
_brain = new Brain();
std::cout << "Dog constructor called\n";
}
Dog::Dog(const Dog &other) : Animal(other)
{
_brain = new Brain(*(other._brain));
std::cout << "Dog copy constructor called\n";
}
Dog &Dog::operator=(const Dog &other)
{
_type = other._type;
delete _brain;
_brain = new Brain(*(other._brain));
std::cout << "Dog copy assignment constructor called\n";
return (*this);
}
Dog::~Dog()
{
delete _brain;
std::cout << "Dog deconstructor called\n";
}
void Dog::makeSound() const
{
std::cout << "Waf Waf Waf\n";
}
std::string Dog::getIdea(int n_idea) const
{
if (n_idea < 0)
return "Negative ideas number is not posible.\n";
else if (n_idea > 99)
return "A dog's brain can have up to 100 ideas.\n";
else
return _brain->ideas[n_idea];
}
void Dog::setIdea(int n_idea, std::string idea)
{
if (n_idea < 0)
std::cout << "Negative idea number is not posible.\n";
else if (n_idea > 99)
std::cout << "A dog's brain can have up to 100 ideas.\n";
else
_brain->ideas[n_idea] = idea;
}