cpp04/ex01/Cat.cpp

62 lines
1.3 KiB
C++

# include "Cat.hpp"
Cat::Cat () : Animal()
{
_type = "Cat";
_brain = new Brain();
std::cout << "Cat constructor called\n";
}
Cat::Cat (std::string type) : Animal(type)
{
_type = type;
_brain = new Brain();
std::cout << "Cat constructor called\n";
}
Cat::Cat(const Cat &other) : Animal()
{
_brain = new Brain(*(other._brain));
std::cout << "Cat copy constructor called\n";
}
Cat &Cat::operator=(const Cat &other)
{
_type = other._type;
delete _brain;
_brain = new Brain(*(other._brain));
std::cout << "Cat copy assignment constructor called\n";
return (*this);
}
Cat::~Cat()
{
delete _brain;
std::cout << "Cat deconstructor called\n";
}
void Cat::makeSound() const
{
std::cout << "miaou miaou miaou (je suis relou) miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou\n";
}
std::string Cat::getIdea(int n_idea) const
{
if (n_idea < 0)
return "Negative ideas number is not posible.\n";
else if (n_idea > 99)
return "A cat's brain can have up to 100 ideas.\n";
else
return _brain->ideas[n_idea];
}
void Cat::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 cat's brain can have up to 100 ideas.\n";
else
_brain->ideas[n_idea] = idea;
}