diff --git a/ex00/Polymorphism b/ex00/Polymorphism index fc647e8..ca468a6 100755 Binary files a/ex00/Polymorphism and b/ex00/Polymorphism differ diff --git a/ex00/WrongAnimal.cpp b/ex00/WrongAnimal.cpp new file mode 100644 index 0000000..418fa70 --- /dev/null +++ b/ex00/WrongAnimal.cpp @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongAnimal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/01 19:14:27 by adjoly #+# #+# */ +/* Updated: 2024/12/04 13:56:34 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "WrongAnimal.hpp" + +WrongAnimal::WrongAnimal(void) { + log("➕", "WrongAnimal", "", "construtor called"); +} + +WrongAnimal::~WrongAnimal() { + log("➖", "WrongAnimal", _type, "destructor called"); +} + +WrongAnimal::WrongAnimal(std::string type) : _type(type) { + log("➕", "WrongAnimal", type, "construtor called"); +} + +WrongAnimal::WrongAnimal(const WrongAnimal &cpy) { + log("➕", "WrongAnimal", _type, "copy construtor called"); + *this = cpy; +} + +WrongAnimal &WrongAnimal::operator=(const WrongAnimal &cpy) { + log("🟰", "WrongAnimal", _type, "copy assignment construtor called"); + if (this != &cpy) { + _type = cpy._type; + } + return (*this); +} + +void WrongAnimal::makeSound(void) const { + log("🔊", "WrongAnimal", "", "making a wrong sound OOOOOOOOOOOOOOOoo"); +} + +std::string WrongAnimal::getType(void) const { + return (_type); +} diff --git a/ex00/WrongAnimal.hpp b/ex00/WrongAnimal.hpp new file mode 100644 index 0000000..14ba80e --- /dev/null +++ b/ex00/WrongAnimal.hpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongAnimal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/30 16:33:08 by adjoly #+# #+# */ +/* Updated: 2024/12/04 13:50:36 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include + +class WrongAnimal { + protected: + std::string _type; + + public: + WrongAnimal(void); + ~WrongAnimal(void); + WrongAnimal(std::string); + WrongAnimal(const WrongAnimal &); + WrongAnimal &operator=(const WrongAnimal &); + + std::string getType(void) const; + + void makeSound(void) const; +}; + +void log(std::string, std::string, std::string, std::string); diff --git a/ex00/WrongCat.cpp b/ex00/WrongCat.cpp new file mode 100644 index 0000000..ca906d9 --- /dev/null +++ b/ex00/WrongCat.cpp @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongCat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/01 19:49:11 by adjoly #+# #+# */ +/* Updated: 2024/12/04 13:49:51 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "WrongCat.hpp" + +WrongCat::WrongCat(void) : Animal("WrongCat"){ + log("➕", "WrongCat", "", "construtor called"); +} + +WrongCat::~WrongCat(void) { + log("➖", "WrongCat", "", "destructor called"); +} + +WrongCat::WrongCat(const WrongCat &cpy) : Animal("WrongCat"){ + log("➕", "WrongCat", _type, "copy construtor called"); + *this = cpy; +} + +WrongCat &WrongCat::operator=(const WrongCat &cpy) { + log("🟰", "WrongCat", "", "copy assignment construtor called"); + if (this != &cpy) { + this->_type = cpy._type; + } + return (*this); +} + +void WrongCat::makeSound(void) const { + log("🔊", "WrongCat", "", "wwwwwwwwooooooooeeeeeeeeemmmmmmm"); +} diff --git a/ex00/WrongCat.hpp b/ex00/WrongCat.hpp new file mode 100644 index 0000000..c512302 --- /dev/null +++ b/ex00/WrongCat.hpp @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongCat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/01 19:06:08 by adjoly #+# #+# */ +/* Updated: 2024/12/04 13:49:47 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "animal.hpp" + +class WrongCat : public Animal { + public: + WrongCat(void); + ~WrongCat(void); + WrongCat(const WrongCat &); + WrongCat &operator=(const WrongCat &); + + void makeSound(void) const; +}; diff --git a/ex00/animal.cpp b/ex00/animal.cpp index dada99c..1378334 100644 --- a/ex00/animal.cpp +++ b/ex00/animal.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/01 19:14:27 by adjoly #+# #+# */ -/* Updated: 2024/12/01 20:22:32 by adjoly ### ########.fr */ +/* Updated: 2024/12/04 13:37:30 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/ex00/animal.hpp b/ex00/animal.hpp index 7fb07d5..4b0f42e 100644 --- a/ex00/animal.hpp +++ b/ex00/animal.hpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/30 16:33:08 by adjoly #+# #+# */ -/* Updated: 2024/12/01 20:22:41 by adjoly ### ########.fr */ +/* Updated: 2024/12/04 14:00:12 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,8 +20,8 @@ class Animal { public: Animal(void); - ~Animal(void); Animal(std::string); + virtual ~Animal(void); Animal(const Animal &); Animal &operator=(const Animal &); diff --git a/ex00/dog.cpp b/ex00/dog.cpp index ac57842..0c7e9fa 100644 --- a/ex00/dog.cpp +++ b/ex00/dog.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/01 20:05:21 by adjoly #+# #+# */ -/* Updated: 2024/12/01 20:18:27 by adjoly ### ########.fr */ +/* Updated: 2024/12/04 14:01:24 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/ex00/main.cpp b/ex00/main.cpp index 2dddb6c..818c12f 100644 --- a/ex00/main.cpp +++ b/ex00/main.cpp @@ -6,32 +6,43 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/30 16:21:28 by adjoly #+# #+# */ -/* Updated: 2024/12/01 20:23:26 by adjoly ### ########.fr */ +/* Updated: 2024/12/04 13:56:06 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ +#include "WrongAnimal.hpp" #include "cat.hpp" #include "dog.hpp" #include -//int main(void) { -// cat cutie; -// dog dogo; -// -// cutie.makeSound(); -// dogo.makeSound(); -//} - int main() { - const Animal* meta = new Animal(); - const Animal* j = new Dog(); - const Animal* i = new Cat(); + { + const Animal* meta = new Animal(); + const Animal* dog = new Dog(); + const Animal* cat = new Cat(); - std::cout << j->getType() << " " << std::endl; - std::cout << i->getType() << " " << std::endl; - i->makeSound(); //will output the cat sound! - j->makeSound(); - meta->makeSound(); + + log("✨", "Animal/Cat", "Type", cat->getType()); + log("✨", "Animal/Dog", "Type", dog->getType()); + cat->makeSound(); //will output the cat sound! + dog->makeSound(); + meta->makeSound(); + + delete meta; + delete cat; + delete dog; + } + { + const WrongAnimal* meta = new WrongAnimal; + const WrongAnimal* wrongcat = new WrongAnimal; + + log("✨", "Animal/WrongCat", "Type", wrongcat->getType()); + + wrongcat->makeSound(); + + delete meta; + delete wrongcat; + } return 0; } diff --git a/ex00/obj/WrongAnimal.d b/ex00/obj/WrongAnimal.d new file mode 100644 index 0000000..8ee6d50 --- /dev/null +++ b/ex00/obj/WrongAnimal.d @@ -0,0 +1,2 @@ +obj/./WrongAnimal.o: WrongAnimal.cpp WrongAnimal.hpp +WrongAnimal.hpp: diff --git a/ex00/obj/WrongCat.d b/ex00/obj/WrongCat.d new file mode 100644 index 0000000..06d30c1 --- /dev/null +++ b/ex00/obj/WrongCat.d @@ -0,0 +1,3 @@ +obj/./WrongCat.o: WrongCat.cpp WrongCat.hpp animal.hpp +WrongCat.hpp: +animal.hpp: diff --git a/ex00/obj/main.d b/ex00/obj/main.d index ece6bf2..857c70a 100644 --- a/ex00/obj/main.d +++ b/ex00/obj/main.d @@ -1,4 +1,5 @@ -obj/./main.o: main.cpp cat.hpp animal.hpp dog.hpp +obj/./main.o: main.cpp WrongAnimal.hpp cat.hpp animal.hpp dog.hpp +WrongAnimal.hpp: cat.hpp: animal.hpp: dog.hpp: