Fixed headers and copy constructor

This commit is contained in:
2025-11-21 12:18:32 +01:00
parent d4d8891a6b
commit c624ced97f
12 changed files with 32 additions and 36 deletions

View File

@@ -28,8 +28,7 @@ Cat::~Cat()
Cat::Cat(const Cat &other) : Animal(other) Cat::Cat(const Cat &other) : Animal(other)
{ {
std::cout << "Cat copied" << std::endl; std::cout << "Cat copied" << std::endl;
this->brain = NULL; this->brain = new Brain(*other.brain);
*this = other;
} }
Cat& Cat::operator=(const Cat &other) Cat& Cat::operator=(const Cat &other)

View File

@@ -28,8 +28,7 @@ Dog::~Dog()
Dog::Dog(const Dog &other) : Animal(other) Dog::Dog(const Dog &other) : Animal(other)
{ {
std::cout << "Dog copied" << std::endl; std::cout << "Dog copied" << std::endl;
this->brain = NULL; this->brain = new Brain(*other.brain);
*this = other;
} }
Dog& Dog::operator=(const Dog &other) Dog& Dog::operator=(const Dog &other)

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* Animal.cpp :+: :+: :+: */ /* WrongAnimal.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */ /* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */ /* Created: 2025/11/21 12:16:12 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */ /* Updated: 2025/11/21 12:16:13 by aortigos ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* Animal.hpp :+: :+: :+: */ /* WrongAnimal.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */ /* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */ /* Created: 2025/11/21 12:16:15 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */ /* Updated: 2025/11/21 12:16:16 by aortigos ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* Animal.cpp :+: :+: :+: */ /* WrongCat.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */ /* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */ /* Created: 2025/11/21 12:16:01 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */ /* Updated: 2025/11/21 12:16:02 by aortigos ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* Animal.hpp :+: :+: :+: */ /* WrongCat.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */ /* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */ /* Created: 2025/11/21 12:16:05 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */ /* Updated: 2025/11/21 12:16:06 by aortigos ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@@ -28,8 +28,7 @@ Cat::~Cat()
Cat::Cat(const Cat &other) : Animal(other) Cat::Cat(const Cat &other) : Animal(other)
{ {
std::cout << "Cat copied" << std::endl; std::cout << "Cat copied" << std::endl;
this->brain = NULL; this->brain = new Brain(*other.brain);
*this = other;
} }
Cat& Cat::operator=(const Cat &other) Cat& Cat::operator=(const Cat &other)

View File

@@ -28,8 +28,7 @@ Dog::~Dog()
Dog::Dog(const Dog &other) : Animal(other) Dog::Dog(const Dog &other) : Animal(other)
{ {
std::cout << "Dog copied" << std::endl; std::cout << "Dog copied" << std::endl;
this->brain = NULL; this->brain = new Brain(*other.brain);
*this = other;
} }
Dog& Dog::operator=(const Dog &other) Dog& Dog::operator=(const Dog &other)

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* Animal.cpp :+: :+: :+: */ /* WrongAnimal.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */ /* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */ /* Created: 2025/11/21 11:43:54 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */ /* Updated: 2025/11/21 11:44:39 by aortigos ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -14,12 +14,12 @@
WrongAnimal::WrongAnimal() : type("WrongAnimal") WrongAnimal::WrongAnimal() : type("WrongAnimal")
{ {
std::cout << "Animal has been created" << std::endl; std::cout << "WrongAnimal has been created" << std::endl;
} }
WrongAnimal::~WrongAnimal() WrongAnimal::~WrongAnimal()
{ {
std::cout << "Animal has been destroyed" << std::endl; std::cout << "WrongAnimal has been destroyed" << std::endl;
} }
WrongAnimal::WrongAnimal(const WrongAnimal &other) WrongAnimal::WrongAnimal(const WrongAnimal &other)

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* Animal.hpp :+: :+: :+: */ /* WrongAnimal.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */ /* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */ /* Created: 2025/11/21 11:43:58 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */ /* Updated: 2025/11/21 11:44:00 by aortigos ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* Animal.cpp :+: :+: :+: */ /* WrongCat.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */ /* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */ /* Created: 2025/11/21 11:44:04 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */ /* Updated: 2025/11/21 11:44:48 by aortigos ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -14,13 +14,13 @@
WrongCat::WrongCat() : WrongAnimal() WrongCat::WrongCat() : WrongAnimal()
{ {
std::cout << "Cat has been created" << std::endl; std::cout << "WrongCat has been created" << std::endl;
this->type = "WrongCat"; this->type = "WrongCat";
} }
WrongCat::~WrongCat() WrongCat::~WrongCat()
{ {
std::cout << "Cat has been destroyed" << std::endl; std::cout << "WrongCat has been destroyed" << std::endl;
} }
WrongCat::WrongCat(const WrongCat &other) : WrongAnimal(other) WrongCat::WrongCat(const WrongCat &other) : WrongAnimal(other)

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* Animal.hpp :+: :+: :+: */ /* WrongCat.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */ /* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */ /* Created: 2025/11/21 11:44:07 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */ /* Updated: 2025/11/21 11:44:08 by aortigos ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */