ex02 finished
This commit is contained in:
51
ex02/Dog/Dog.cpp
Normal file
51
ex02/Dog/Dog.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Dog.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 "Dog.hpp"
|
||||
|
||||
Dog::Dog() : Animal()
|
||||
{
|
||||
std::cout << "Dog has been created" << std::endl;
|
||||
this->type = "Dog";
|
||||
this->brain = new Brain();
|
||||
}
|
||||
|
||||
Dog::~Dog()
|
||||
{
|
||||
std::cout << "Dog has been destroyed" << std::endl;
|
||||
delete (this->brain);
|
||||
}
|
||||
|
||||
Dog::Dog(const Dog &other) : Animal(other)
|
||||
{
|
||||
std::cout << "Dog copied" << std::endl;
|
||||
this->brain = NULL;
|
||||
*this = other;
|
||||
}
|
||||
|
||||
Dog& Dog::operator=(const Dog &other)
|
||||
{
|
||||
std::cout << "Dog 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 Dog::makeSound() const
|
||||
{
|
||||
std::cout << "Woof!" << std::endl;
|
||||
}
|
||||
38
ex02/Dog/Dog.hpp
Normal file
38
ex02/Dog/Dog.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Dog.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 DOG_HPP
|
||||
|
||||
# define DOG_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include "../Animal/Animal.hpp"
|
||||
# include "../Brain/Brain.hpp"
|
||||
|
||||
class Dog : public Animal
|
||||
{
|
||||
private:
|
||||
Brain *brain;
|
||||
|
||||
public:
|
||||
Dog();
|
||||
~Dog();
|
||||
Dog(const Dog &other);
|
||||
Dog& operator=(const Dog &other);
|
||||
|
||||
void makeSound() const;
|
||||
|
||||
Brain* getBrain() const { return brain; }
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user