recreation of ex01
This commit is contained in:
parent
55a7c73656
commit
cfee0e2ec4
@ -1,25 +1,25 @@
|
|||||||
CXX = c++
|
CXX = c++
|
||||||
CXXFLAGS = -std=c++98 -Wall -Wextra -Werror -g -O0
|
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
|
||||||
SRCDIR = src
|
SRCDIR = src
|
||||||
OBJDIR = obj
|
OBJDIR = obj
|
||||||
BINDIR = bin
|
NAME = ex01
|
||||||
EXECUTABLE = zombie
|
|
||||||
|
|
||||||
SRCS = $(wildcard $(SRCDIR)/*.cpp)
|
SRCS = $(wildcard $(SRCDIR)/*.cpp)
|
||||||
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
|
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
|
||||||
|
|
||||||
all: $(BINDIR)/$(EXECUTABLE)
|
all: $(NAME)
|
||||||
|
|
||||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
||||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
mkdir -p obj
|
||||||
|
$(CXX) $(CPPFLAGS) -c $< -o $@
|
||||||
|
|
||||||
$(BINDIR)/$(EXECUTABLE): $(OBJS)
|
$(NAME): $(OBJS)
|
||||||
$(CXX) $(CXXFLAGS) $^ -o $@
|
$(CXX) $(CPPFLAGS) $^ -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(OBJDIR)/*.o
|
rm -rf $(OBJDIR)/*.o
|
||||||
|
|
||||||
fclean: clean
|
fclean: clean
|
||||||
rm -fr $(BINDIR)/$(EXECUTABLE)
|
rm -fr $(NAME)
|
||||||
|
|
||||||
re: fclean all
|
re: fclean all
|
||||||
|
BIN
ex01/bin/zombie
BIN
ex01/bin/zombie
Binary file not shown.
@ -1,30 +1,40 @@
|
|||||||
#include "Zombie.hpp"
|
#include "./Zombie.hpp"
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
Zombie::Zombie(std::string name)
|
|
||||||
{
|
|
||||||
this->name = name;
|
|
||||||
std::cout << this->name << ": " << "Zombie()" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
Zombie::Zombie()
|
Zombie::Zombie()
|
||||||
{
|
{
|
||||||
this->name = "";
|
std::cout << "Zombie()" << std::endl;
|
||||||
std::cout << this->name << ": " << "Zombie()" << std::endl;
|
}
|
||||||
|
|
||||||
|
Zombie::Zombie(const std::string& name)
|
||||||
|
{
|
||||||
|
std::cout << "Zombie(" << name << ")" << std::endl;
|
||||||
|
this->_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
Zombie::Zombie(const Zombie& src)
|
||||||
|
{
|
||||||
|
*this = src;
|
||||||
}
|
}
|
||||||
|
|
||||||
Zombie::~Zombie()
|
Zombie::~Zombie()
|
||||||
{
|
{
|
||||||
std::cout << this->name << ": " << "~Zombie()" << std::endl;
|
std::cout << "~Zombie()" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Zombie::announce() const
|
Zombie& Zombie::operator=(const Zombie& src)
|
||||||
{
|
{
|
||||||
std::cout << this->name << ": " << "BraiiiiiiinnnzzzZ..." << std::endl;
|
this->_name = src._name;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Zombie::setName(std::string name)
|
void Zombie::announe()
|
||||||
{
|
{
|
||||||
this->name = name;
|
std::cout << this->_name << ": BraiiiiiiinnnzzzZ..." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Zombie::setName(const std::string &name)
|
||||||
|
{
|
||||||
|
this->_name = name;
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class Zombie {
|
class Zombie
|
||||||
|
{
|
||||||
private:
|
private:
|
||||||
std::string name;
|
std::string _name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Zombie(std::string name);
|
Zombie(const Zombie& src);
|
||||||
Zombie();
|
Zombie();
|
||||||
|
Zombie(const std::string& name);
|
||||||
~Zombie();
|
~Zombie();
|
||||||
|
|
||||||
void setName(std::string name);
|
Zombie& operator=(const Zombie& src);
|
||||||
void announce(void) const;
|
|
||||||
|
|
||||||
|
void announe(void);
|
||||||
|
void setName(const std::string& name);
|
||||||
};
|
};
|
||||||
|
|
||||||
Zombie* zombieHorde(int N, std::string name);
|
Zombie* zombieHorde(int N, std::string name);
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
#include "Zombie.hpp"
|
#include "Zombie.hpp"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
Zombie* jean;
|
Zombie* jean = zombieHorde(2, "jean");
|
||||||
Zombie pierre("Pierre");
|
|
||||||
|
|
||||||
jean = new Zombie("jean");
|
|
||||||
jean->announce();
|
|
||||||
delete jean;
|
|
||||||
jean = zombieHorde(3, "jean");
|
|
||||||
delete[] jean;
|
delete[] jean;
|
||||||
|
|
||||||
|
Zombie* bob = zombieHorde(-1, "bob");
|
||||||
|
if (bob == NULL)
|
||||||
|
return 1;
|
||||||
|
bob->announe();
|
||||||
|
delete[] bob;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
#include "Zombie.hpp"
|
#include "Zombie.hpp"
|
||||||
#include <cstddef>
|
#include <string>
|
||||||
|
|
||||||
Zombie* zombieHorde(int N, std::string name)
|
Zombie* zombieHorde(int N, std::string name)
|
||||||
{
|
{
|
||||||
size_t i;
|
|
||||||
Zombie *zombies;
|
|
||||||
|
|
||||||
if (0 > N)
|
if (0 > N)
|
||||||
return (NULL);
|
return NULL;
|
||||||
zombies = new Zombie[N];
|
Zombie* zombies = new Zombie[N];
|
||||||
for (i = 0; i < (size_t) N; i++)
|
for (int i = 0; i < N; i++)
|
||||||
|
{
|
||||||
zombies[i].setName(name);
|
zombies[i].setName(name);
|
||||||
return (zombies);
|
zombies[i].announe();
|
||||||
|
}
|
||||||
|
return zombies;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user