diff --git a/d01/ex00/Makefile b/d01/ex00/Makefile new file mode 100644 index 0000000..3fee7a0 --- /dev/null +++ b/d01/ex00/Makefile @@ -0,0 +1,64 @@ +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . name = value . name is case sensitive # +# VARIABLES . or name = value \ . use VPATH only for .c # +# . value . or .cpp # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +NAME = zombie + +CC = clang++ +CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -std=c++98 + +VPATH = $(D_SRCS) + +LIBS = + +INCLUDES = -I$(D_HEADERS) + +D_SRCS = . +SRCS = main.cpp \ + Zombie.cpp \ + newZombie.cpp \ + randomChump.cpp + +D_HEADERS = . +HEADERS = Zombie.hpp + +D_OBJS = builds +OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o) + +RM_D_OBJS = rm -rf $(D_OBJS) +ifeq "$(D_OBJS)" "." +RM_D_OBJS = +endif + + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . target: prerequisites . $@ : target # +# RULES . recipe . $< : 1st prerequisite # +# . recipe . $^ : all prerequisites # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +all: $(NAME) + +$(D_OBJS)/%.o: %.cpp | $(D_OBJS) + $(CC) $(CFLAGS) -c $< -o $@ + +$(D_OBJS): + mkdir $@ + +$(OBJS): $(HEADERS:%=$(D_HEADERS)/%) + +$(NAME): $(OBJS) + $(CC) $(OBJS) -o $@ $(LIBS) + +clean: + rm -f $(OBJS) + +fclean: clean + rm -f $(NAME) + $(RM_D_OBJS) + +re: fclean all + +.PHONY : all clean fclean re bonus run valgrind diff --git a/d01/ex00/Zombie.cpp b/d01/ex00/Zombie.cpp new file mode 100644 index 0000000..93b1b0c --- /dev/null +++ b/d01/ex00/Zombie.cpp @@ -0,0 +1,13 @@ +#include "Zombie.hpp" + +Zombie::Zombie( std::string name ) { + this->_name = name; + std::cout << this->_name << " has been created" << std::endl; +} +Zombie::~Zombie() { + std::cout << this->_name << " has been destroyed" << std::endl; +} + +void Zombie::announce( void ) { + std::cout << this->_name << ": BraiiiiiiinnnzzzZ..." << std::endl; +} diff --git a/d01/ex00/Zombie.hpp b/d01/ex00/Zombie.hpp new file mode 100644 index 0000000..f8cc0af --- /dev/null +++ b/d01/ex00/Zombie.hpp @@ -0,0 +1,22 @@ +#ifndef ZOMBIE_HPP +# define ZOMBIE_HPP + +#include +#include + +class Zombie { + +public: + + Zombie( std::string name ); + ~Zombie(); + + void announce( void ); + +private: + + std::string _name; + +}; + +#endif diff --git a/d01/ex00/main.cpp b/d01/ex00/main.cpp new file mode 100644 index 0000000..15667f8 --- /dev/null +++ b/d01/ex00/main.cpp @@ -0,0 +1,25 @@ +#include "Zombie.hpp" + +Zombie* newZombie( std::string name ); +void randomChump( std::string name ); + +int main(void) +{ + Zombie* zombie_one; + Zombie* zombie_two; + + zombie_one = newZombie("Heap1"); + zombie_one->announce(); + delete zombie_one; + zombie_one = newZombie("Heap2"); + zombie_two = newZombie("Heap3"); + zombie_one->announce(); + zombie_two->announce(); + randomChump("Stack1"); + randomChump("Stack2"); + delete zombie_two; + randomChump("Stack3"); + delete zombie_one; + + return (0); +} diff --git a/d01/ex00/newZombie.cpp b/d01/ex00/newZombie.cpp new file mode 100644 index 0000000..117147e --- /dev/null +++ b/d01/ex00/newZombie.cpp @@ -0,0 +1,12 @@ +#include "Zombie.hpp" + +Zombie *newZombie( std::string name ) { + + Zombie *zomb; + + zomb = new Zombie( name ); + return zomb; + +} + + diff --git a/d01/ex00/randomChump.cpp b/d01/ex00/randomChump.cpp new file mode 100644 index 0000000..60bf2f8 --- /dev/null +++ b/d01/ex00/randomChump.cpp @@ -0,0 +1,11 @@ +#include "Zombie.hpp" + +void randomChump( std::string name ) { + + Zombie zomb( name ); + + zomb.announce(); + return; + +} + diff --git a/d01/ex00/zombie b/d01/ex00/zombie new file mode 100755 index 0000000..f5f3f12 Binary files /dev/null and b/d01/ex00/zombie differ