cpp/cpp04/ex02/Cat.cpp
2022-07-19 12:59:21 +02:00

68 lines
1.9 KiB
C++

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Cat.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 02:11:37 by apommier #+# #+# */
/* Updated: 2022/07/17 19:03:24 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "Cat.hpp"
Cat::Cat() : Animal()
{
std::cout << "Cat Default constructor called" << std::endl;
this->type = "Cat";
this->_Brain = new Brain;
}
Cat::Cat(const Cat& copy) : Animal(copy)
{
std::cout << "Cat Copy constructor called" << std::endl;
this->type = copy.getType();
//this->_Brain = copy.getType();
}
Cat::~Cat()
{
std::cout << "Cat Destructor called" << std::endl;
delete this->_Brain;
}
void Cat::makeSound(void) const
{
std::cout << "Meow\n";
}
Cat &Cat::operator=(const Cat& rhs)
{
std::cout << "Cat assignement operator called" << std::endl;
if (&rhs != this)
{
this->type = rhs.getType();
delete this->_Brain;
this->_Brain = new Brain(*rhs._Brain);
}
return (*this);
}
Animal &Cat::operator=( const Animal &rhs)
{
std::cout << "Cat assignement operator called" << std::endl;
if (&rhs != this)
{
this->type = rhs.getType();
delete this->_Brain;
this->_Brain = new Brain(*rhs.getBrain());
}
return (*this);
}
Brain *Cat::getBrain() const
{
return (this->_Brain);
}