d01 ex00 ok
This commit is contained in:
64
d01/ex00/Makefile
Normal file
64
d01/ex00/Makefile
Normal file
@@ -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
|
||||
13
d01/ex00/Zombie.cpp
Normal file
13
d01/ex00/Zombie.cpp
Normal file
@@ -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;
|
||||
}
|
||||
22
d01/ex00/Zombie.hpp
Normal file
22
d01/ex00/Zombie.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef ZOMBIE_HPP
|
||||
# define ZOMBIE_HPP
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
class Zombie {
|
||||
|
||||
public:
|
||||
|
||||
Zombie( std::string name );
|
||||
~Zombie();
|
||||
|
||||
void announce( void );
|
||||
|
||||
private:
|
||||
|
||||
std::string _name;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
25
d01/ex00/main.cpp
Normal file
25
d01/ex00/main.cpp
Normal file
@@ -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);
|
||||
}
|
||||
12
d01/ex00/newZombie.cpp
Normal file
12
d01/ex00/newZombie.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "Zombie.hpp"
|
||||
|
||||
Zombie *newZombie( std::string name ) {
|
||||
|
||||
Zombie *zomb;
|
||||
|
||||
zomb = new Zombie( name );
|
||||
return zomb;
|
||||
|
||||
}
|
||||
|
||||
|
||||
11
d01/ex00/randomChump.cpp
Normal file
11
d01/ex00/randomChump.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "Zombie.hpp"
|
||||
|
||||
void randomChump( std::string name ) {
|
||||
|
||||
Zombie zomb( name );
|
||||
|
||||
zomb.announce();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
BIN
d01/ex00/zombie
Executable file
BIN
d01/ex00/zombie
Executable file
Binary file not shown.
Reference in New Issue
Block a user