ex02 finished

This commit is contained in:
2025-11-10 20:50:53 +01:00
parent 2438853723
commit fa95f2b5b6
14 changed files with 567 additions and 0 deletions

51
ex02/Cat/Cat.cpp Normal file
View File

@@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Cat.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "Cat.hpp"
Cat::Cat() : Animal()
{
std::cout << "Cat has been created" << std::endl;
this->type = "Cat";
this->brain = new Brain();
}
Cat::~Cat()
{
std::cout << "Cat has been destroyed" << std::endl;
delete (this->brain);
}
Cat::Cat(const Cat &other) : Animal(other)
{
std::cout << "Cat copied" << std::endl;
this->brain = NULL;
*this = other;
}
Cat& Cat::operator=(const Cat &other)
{
std::cout << "Cat copy assignment called" << std::endl;
if (this != &other)
{
Animal::operator=(other);
if (this->brain)
delete (this->brain);
this->brain = new Brain(*other.brain);
}
return (*this);
}
void Cat::makeSound() const
{
std::cout << "Meow!" << std::endl;
}

37
ex02/Cat/Cat.hpp Normal file
View File

@@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Cat.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CAT_HPP
# define CAT_HPP
# include <iostream>
# include "../Animal/Animal.hpp"
# include "../Brain/Brain.hpp"
class Cat : public Animal
{
private:
Brain *brain;
public:
Cat();
~Cat();
Cat(const Cat &other);
Cat& operator=(const Cat &other);
void makeSound() const;
Brain* getBrain() const { return brain; }
};
#endif