diff --git a/.gitignore b/.gitignore index 336712c..e6e7059 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ *.o obj/ Polymorphism +compile_commands.json +.cache +*.d diff --git a/ex00/animal.cpp b/ex00/Animal.cpp similarity index 90% rename from ex00/animal.cpp rename to ex00/Animal.cpp index 1378334..efced5c 100644 --- a/ex00/animal.cpp +++ b/ex00/Animal.cpp @@ -1,16 +1,16 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* animal.cpp :+: :+: :+: */ +/* Animal.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/01 19:14:27 by adjoly #+# #+# */ -/* Updated: 2024/12/04 13:37:30 by adjoly ### ########.fr */ +/* Updated: 2024/12/06 15:52:01 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ -#include "animal.hpp" +#include "Animal.hpp" Animal::Animal(void) { log("➕", "Animal", "", "construtor called"); diff --git a/ex00/animal.hpp b/ex00/Animal.hpp similarity index 100% rename from ex00/animal.hpp rename to ex00/Animal.hpp diff --git a/ex00/cat.cpp b/ex00/Cat.cpp similarity index 89% rename from ex00/cat.cpp rename to ex00/Cat.cpp index e23227b..f2662a5 100644 --- a/ex00/cat.cpp +++ b/ex00/Cat.cpp @@ -1,16 +1,16 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* cat.cpp :+: :+: :+: */ +/* Cat.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/01 19:49:11 by adjoly #+# #+# */ -/* Updated: 2024/12/01 20:18:55 by adjoly ### ########.fr */ +/* Updated: 2024/12/06 15:52:10 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ -#include "cat.hpp" +#include "Cat.hpp" Cat::Cat(void) : Animal("Cat"){ log("➕", "Cat", "", "construtor called"); diff --git a/ex00/cat.hpp b/ex00/Cat.hpp similarity index 86% rename from ex00/cat.hpp rename to ex00/Cat.hpp index 399a22f..81bc2b3 100644 --- a/ex00/cat.hpp +++ b/ex00/Cat.hpp @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* cat.hpp :+: :+: :+: */ +/* Cat.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/01 19:06:08 by adjoly #+# #+# */ -/* Updated: 2024/12/01 20:18:42 by adjoly ### ########.fr */ +/* Updated: 2024/12/06 15:52:20 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once -#include "animal.hpp" +#include "Animal.hpp" class Cat : public Animal { public: diff --git a/ex00/dog.cpp b/ex00/Dog.cpp similarity index 89% rename from ex00/dog.cpp rename to ex00/Dog.cpp index 0c7e9fa..1116102 100644 --- a/ex00/dog.cpp +++ b/ex00/Dog.cpp @@ -1,16 +1,16 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* dog.cpp :+: :+: :+: */ +/* Dog.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/01 20:05:21 by adjoly #+# #+# */ -/* Updated: 2024/12/04 14:01:24 by adjoly ### ########.fr */ +/* Updated: 2024/12/06 15:52:26 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ -#include "dog.hpp" +#include "Dog.hpp" Dog::Dog(void) : Animal("Dog"){ log("➕", "Dog", "", "construtor called"); diff --git a/ex00/dog.hpp b/ex00/Dog.hpp similarity index 86% rename from ex00/dog.hpp rename to ex00/Dog.hpp index a32cc7c..f3c09de 100644 --- a/ex00/dog.hpp +++ b/ex00/Dog.hpp @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* dog.hpp :+: :+: :+: */ +/* Dog.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/01 20:06:20 by adjoly #+# #+# */ -/* Updated: 2024/12/01 20:18:35 by adjoly ### ########.fr */ +/* Updated: 2024/12/06 15:52:35 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once -#include "animal.hpp" +#include "Animal.hpp" class Dog : public Animal { public: diff --git a/ex00/log.cpp b/ex00/Log.cpp similarity index 100% rename from ex00/log.cpp rename to ex00/Log.cpp diff --git a/ex00/WrongCat.cpp b/ex00/WrongCat.cpp index ca906d9..1121b3c 100644 --- a/ex00/WrongCat.cpp +++ b/ex00/WrongCat.cpp @@ -6,13 +6,13 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/01 19:49:11 by adjoly #+# #+# */ -/* Updated: 2024/12/04 13:49:51 by adjoly ### ########.fr */ +/* Updated: 2024/12/06 15:55:37 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "WrongCat.hpp" -WrongCat::WrongCat(void) : Animal("WrongCat"){ +WrongCat::WrongCat(void) : WrongAnimal("WrongCat"){ log("➕", "WrongCat", "", "construtor called"); } @@ -20,7 +20,7 @@ WrongCat::~WrongCat(void) { log("➖", "WrongCat", "", "destructor called"); } -WrongCat::WrongCat(const WrongCat &cpy) : Animal("WrongCat"){ +WrongCat::WrongCat(const WrongCat &cpy) : WrongAnimal("WrongCat"){ log("➕", "WrongCat", _type, "copy construtor called"); *this = cpy; } diff --git a/ex00/WrongCat.hpp b/ex00/WrongCat.hpp index c512302..6dd78a2 100644 --- a/ex00/WrongCat.hpp +++ b/ex00/WrongCat.hpp @@ -6,15 +6,15 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/01 19:06:08 by adjoly #+# #+# */ -/* Updated: 2024/12/04 13:49:47 by adjoly ### ########.fr */ +/* Updated: 2024/12/06 15:55:47 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once -#include "animal.hpp" +#include "WrongAnimal.hpp" -class WrongCat : public Animal { +class WrongCat : public WrongAnimal { public: WrongCat(void); ~WrongCat(void); diff --git a/ex00/main.cpp b/ex00/main.cpp index 818c12f..c54872b 100644 --- a/ex00/main.cpp +++ b/ex00/main.cpp @@ -6,14 +6,13 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/30 16:21:28 by adjoly #+# #+# */ -/* Updated: 2024/12/04 13:56:06 by adjoly ### ########.fr */ +/* Updated: 2024/12/06 16:02:36 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "WrongAnimal.hpp" -#include "cat.hpp" -#include "dog.hpp" -#include +#include "Cat.hpp" +#include "Dog.hpp" int main() { { @@ -21,7 +20,6 @@ int main() { const Animal* dog = new Dog(); const Animal* cat = new Cat(); - log("✨", "Animal/Cat", "Type", cat->getType()); log("✨", "Animal/Dog", "Type", dog->getType()); cat->makeSound(); //will output the cat sound! diff --git a/ex01/Animal.cpp b/ex01/Animal.cpp new file mode 100644 index 0000000..a252c84 --- /dev/null +++ b/ex01/Animal.cpp @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/01 19:14:27 by adjoly #+# #+# */ +/* Updated: 2024/12/06 15:53:00 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Animal.hpp" + +Animal::Animal(void) { + log("➕", "Animal", "", "construtor called"); +} + +Animal::~Animal() { + log("➖", "Animal", _type, "destructor called"); +} + +Animal::Animal(std::string type) : _type(type) { + log("➕", "Animal", type, "construtor called"); +} + +Animal::Animal(const Animal &cpy) { + log("➕", "Animal", _type, "copy construtor called"); + *this = cpy; +} + +Animal &Animal::operator=(const Animal &cpy) { + log("🟰", "Animal", _type, "copy assignment construtor called"); + if (this != &cpy) { + _type = cpy._type; + } + return (*this); +} + +void Animal::makeSound(void) const { + log("🔊", "Animal", "", "making a sound MEOWMEOW"); +} + +std::string Animal::getType(void) const { + return (_type); +} diff --git a/ex01/Animal.hpp b/ex01/Animal.hpp new file mode 100644 index 0000000..b4b2183 --- /dev/null +++ b/ex01/Animal.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/30 16:33:08 by adjoly #+# #+# */ +/* Updated: 2024/12/06 15:53:05 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include +#include "Log.hpp" + +class Animal { + protected: + std::string _type; + + public: + Animal(void); + Animal(std::string); + virtual ~Animal(void); + Animal(const Animal &); + Animal &operator=(const Animal &); + + std::string getType(void) const; + + virtual void makeSound(void) const; +}; diff --git a/ex01/Brain.cpp b/ex01/Brain.cpp new file mode 100644 index 0000000..24a3af4 --- /dev/null +++ b/ex01/Brain.cpp @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Brain.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/06 11:47:20 by adjoly #+# #+# */ +/* Updated: 2024/12/06 15:53:11 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Brain.hpp" + +Brain::Brain(void) { + log("➕", "Brain", "", "construtor called"); +} + +Brain::~Brain(void) { + log("➖", "Brain", "", "destructor called"); +} + +Brain::Brain(const Brain &cpy) { + log("➕", "Brain", "", "copy construtor called"); + *this = cpy; +} + +Brain &Brain::operator=(const Brain &cpy) { + log("🟰", "Brain", "", "copy assignment construtor called"); + if (this != &cpy) { + for (uint i = 0; i < 100; i++) { + this->_ideas[i] = cpy._ideas[i]; + } + } + return (*this); +} diff --git a/ex01/Brain.hpp b/ex01/Brain.hpp new file mode 100644 index 0000000..3454fa5 --- /dev/null +++ b/ex01/Brain.hpp @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Brain.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/06 11:35:05 by adjoly #+# #+# */ +/* Updated: 2024/12/06 15:53:18 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include +#include "Log.hpp" + +class Brain { + public: + Brain(void); + ~Brain(void); + Brain(const Brain &); + Brain &operator=(const Brain &); + + std::string _ideas[100]; +}; diff --git a/ex01/Cat.cpp b/ex01/Cat.cpp new file mode 100644 index 0000000..7e946fd --- /dev/null +++ b/ex01/Cat.cpp @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/01 19:49:11 by adjoly #+# #+# */ +/* Updated: 2024/12/06 15:53:23 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Cat.hpp" + +Cat::Cat(void) : Animal("Cat"){ + _brain = new Brain(); + log("➕", "Cat", "", "construtor called"); +} + +Cat::~Cat(void) { + delete _brain; + log("➖", "Cat", "", "destructor called"); +} + +Cat::Cat(const Cat &cpy) : Animal("Cat"){ + log("➕", "Cat", _type, "copy construtor called"); + *this = cpy; +} + +Cat &Cat::operator=(const Cat &cpy) { + log("🟰", "Cat", "", "copy assignment construtor called"); + if (this != &cpy) { + this->_type = cpy._type; + } + return (*this); +} + +void Cat::makeSound(void) const { + log("🔊", "Cat", "", "Mmmmmmeeeeeeeeoooooooowwwwww"); +} + +void Cat::setIdea(std::string idea, uint i) { + _brain->_ideas[i] = idea; +} + +std::string Cat::getIdea(uint i) { + return (_brain->_ideas[i]); +} diff --git a/ex01/Cat.hpp b/ex01/Cat.hpp new file mode 100644 index 0000000..2162ca9 --- /dev/null +++ b/ex01/Cat.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/01 19:06:08 by adjoly #+# #+# */ +/* Updated: 2024/12/06 15:53:30 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "Animal.hpp" +#include "Brain.hpp" + +class Cat : public Animal { + private: + Brain *_brain; + public: + Cat(void); + ~Cat(void); + Cat(const Cat &); + Cat &operator=(const Cat &); + + void makeSound(void) const; + void setIdea(std::string, uint); + std::string getIdea(uint); +}; diff --git a/ex01/Dog.cpp b/ex01/Dog.cpp new file mode 100644 index 0000000..433a39e --- /dev/null +++ b/ex01/Dog.cpp @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/01 20:05:21 by adjoly #+# #+# */ +/* Updated: 2024/12/06 15:53:35 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Dog.hpp" + +Dog::Dog(void) : Animal("Dog"){ + _brain = new Brain(); + log("➕", "Dog", "", "construtor called"); +} + +Dog::~Dog(void) { + delete _brain; + log("➖", "Dog", "", "destructor called"); +} + +Dog::Dog(const Dog &cpy) : Animal("Dog"){ + log("➕", "Dog", _type, "copy construtor called"); + *this = cpy; +} + +Dog &Dog::operator=(const Dog &cpy) { + log("🟰", "Dog", "", "copy assignment construtor called"); + if (this != &cpy) { + this->_type = cpy._type; + } + return (*this); +} + +void Dog::makeSound(void) const { + log("🔊", "Dog", "", "woof"); +} + +void Dog::setIdea(std::string idea, uint i) { + _brain->_ideas[i] = idea; +} + +std::string Dog::getIdea(uint i) { + return (_brain->_ideas[i]); +} diff --git a/ex01/Dog.hpp b/ex01/Dog.hpp new file mode 100644 index 0000000..ceb53cb --- /dev/null +++ b/ex01/Dog.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/01 20:06:20 by adjoly #+# #+# */ +/* Updated: 2024/12/06 15:53:41 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "Animal.hpp" +#include "Brain.hpp" + +class Dog : public Animal { + private: + Brain *_brain; + public: + Dog(void); + ~Dog(void); + Dog(const Dog &); + Dog &operator=(const Dog &); + + void makeSound(void) const; + void setIdea(std::string, uint); + std::string getIdea(uint); +}; diff --git a/ex01/Log.cpp b/ex01/Log.cpp new file mode 100644 index 0000000..9dbf721 --- /dev/null +++ b/ex01/Log.cpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* log.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/30 16:30:53 by adjoly #+# #+# */ +/* Updated: 2024/11/30 16:32:37 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +void log(std::string emoji, std::string what, std::string who, std::string str) { + if (who.empty()) + std::cout << "「" << emoji << "」" << what << ": " << str << std::endl; + else + std::cout << "「" << emoji << "」" << what << "(" << who << "): " << str << std::endl; +} + diff --git a/ex01/Log.hpp b/ex01/Log.hpp new file mode 100644 index 0000000..5b8e7fe --- /dev/null +++ b/ex01/Log.hpp @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* log.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/06 12:01:21 by adjoly #+# #+# */ +/* Updated: 2024/12/06 13:12:13 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include + +typedef unsigned int uint; + +void log(std::string, std::string, std::string, std::string); diff --git a/ex01/Makefile b/ex01/Makefile new file mode 100644 index 0000000..db502d5 --- /dev/null +++ b/ex01/Makefile @@ -0,0 +1,56 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: adjoly +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/10/25 16:09:27 by adjoly #+# #+# # +# Updated: 2024/12/06 12:07:06 by adjoly ### ########.fr # +# # +# **************************************************************************** # + +SHELL = bash + +NAME = Settheworldonfire + +CC = c++ + +OBJSDIR = obj/ + +SRCS = $(shell find . -name '*.cpp') + +OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o)) + +FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP + +RED = \033[0;31m +GREEN = \033[0;32m +YELLOW = \033[1;33m +PURPLE = \e[0;35m +NC = \033[0m +DELETE = \x1B[2K\r + +all: $(NAME) + +$(NAME): $(OBJS) + @$(CC) $(FLAGS) $(OBJS) -o $(NAME) + @printf "$(YELLOW)「✨」($(NAME)) Program compiled\n" + +$(OBJSDIR)%.o: %.cpp + @mkdir -p $(@D) + @$(CC) $(FLAGS) -c $< -o $@ + @printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n" + +clean: + @rm -f $(OBJS) + @printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n" + +fclean: clean + @rm -f $(NAME) + @rm -Rf $(OBJSDIR) + @printf "$(RED)「🗑️」($(NAME)) Program deleted\n" + +re: fclean all + +.PHONY: clean fclean all re diff --git a/ex01/WrongAnimal.cpp b/ex01/WrongAnimal.cpp new file mode 100644 index 0000000..418fa70 --- /dev/null +++ b/ex01/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/ex01/WrongAnimal.hpp b/ex01/WrongAnimal.hpp new file mode 100644 index 0000000..14ba80e --- /dev/null +++ b/ex01/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/ex01/WrongCat.cpp b/ex01/WrongCat.cpp new file mode 100644 index 0000000..1121b3c --- /dev/null +++ b/ex01/WrongCat.cpp @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongCat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/01 19:49:11 by adjoly #+# #+# */ +/* Updated: 2024/12/06 15:55:37 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "WrongCat.hpp" + +WrongCat::WrongCat(void) : WrongAnimal("WrongCat"){ + log("➕", "WrongCat", "", "construtor called"); +} + +WrongCat::~WrongCat(void) { + log("➖", "WrongCat", "", "destructor called"); +} + +WrongCat::WrongCat(const WrongCat &cpy) : WrongAnimal("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/ex01/WrongCat.hpp b/ex01/WrongCat.hpp new file mode 100644 index 0000000..6dd78a2 --- /dev/null +++ b/ex01/WrongCat.hpp @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongCat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/01 19:06:08 by adjoly #+# #+# */ +/* Updated: 2024/12/06 15:55:47 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "WrongAnimal.hpp" + +class WrongCat : public WrongAnimal { + public: + WrongCat(void); + ~WrongCat(void); + WrongCat(const WrongCat &); + WrongCat &operator=(const WrongCat &); + + void makeSound(void) const; +}; diff --git a/ex01/main.cpp b/ex01/main.cpp new file mode 100644 index 0000000..e79b998 --- /dev/null +++ b/ex01/main.cpp @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/06 11:20:59 by adjoly #+# #+# */ +/* Updated: 2024/12/06 15:58:25 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Dog.hpp" +#include "Cat.hpp" + +int main() { + const Animal* dog = new Dog(); + Cat* cat = new Cat(); + + cat->setIdea("I want to eat", 0); + cat->setIdea("I want to eat", 1); + cat->setIdea("I want to eat", 2); + cat->setIdea("I want to eat", 3); + cat->setIdea("I want to eat", 4); + cat->setIdea("I want to eat", 5); + cat->setIdea("I want to eat", 6); + dog->makeSound(); + cat->makeSound(); + log("🥩", "Idea", "Cat", cat->getIdea(0)); + log("🥩", "Idea", "Cat", cat->getIdea(1)); + log("🥩", "Idea", "Cat", cat->getIdea(2)); + log("🥩", "Idea", "Cat", cat->getIdea(3)); + log("🥩", "Idea", "Cat", cat->getIdea(4)); + log("🥩", "Idea", "Cat", cat->getIdea(5)); + log("🥩", "Idea", "Cat", cat->getIdea(6)); + + delete cat; + delete dog; + + return 0; +} diff --git a/flake.nix b/flake.nix index 8253a7a..f576ede 100644 --- a/flake.nix +++ b/flake.nix @@ -18,9 +18,6 @@ default = pkgs.mkShell.override {} { - buildInputs = with pkgs;[ - - ]; hardeningDisable = [ "all" ]; packages = with pkgs; [ gcc11