recreation of ex00

This commit is contained in:
starnakin 2023-07-12 02:30:18 +02:00
parent dcfb2af057
commit 55a7c73656
6 changed files with 56 additions and 39 deletions

View File

@ -1,25 +1,25 @@
CXX = c++
CXXFLAGS = -std=c++98 -Wall -Wextra -Werror -g -O0
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
SRCDIR = src
OBJDIR = obj
BINDIR = bin
EXECUTABLE = zombie
NAME = ex00
SRCS = $(wildcard $(SRCDIR)/*.cpp)
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
all: $(BINDIR)/$(EXECUTABLE)
all: $(NAME)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
mkdir -p obj
$(CXX) $(CPPFLAGS) -c $< -o $@
$(BINDIR)/$(EXECUTABLE): $(OBJS)
$(CXX) $(CXXFLAGS) $^ -o $@
$(NAME): $(OBJS)
$(CXX) $(CPPFLAGS) $^ -o $@
clean:
rm -rf $(OBJDIR)/*.o
fclean: clean
rm -fr $(BINDIR)/$(EXECUTABLE)
rm -fr $(NAME)
re: fclean all

View File

@ -1,19 +1,35 @@
#include "Zombie.hpp"
#include <string>
#include "./Zombie.hpp"
#include <iostream>
#include <string>
Zombie::Zombie(std::string name)
Zombie::Zombie()
{
this->name = name;
std::cout << this->name << ": " << "Zombie()" << std::endl;
std::cout << "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()
{
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::announe()
{
std::cout << this->_name << ": BraiiiiiiinnnzzzZ..." << std::endl;
}

View File

@ -1,18 +1,22 @@
#pragma once
#include <string>
class Zombie {
class Zombie
{
private:
std::string name;
std::string _name;
public:
Zombie(std::string name);
Zombie(const Zombie& src);
Zombie();
Zombie(const std::string& name);
~Zombie();
void announce(void) const;
void setName(std::string name);
Zombie& operator=(const Zombie& src);
void announe(void);
};
Zombie* newZombie(std::string name);
void randomChump(std::string name);
Zombie* newZombie(std::string name);

View File

@ -2,11 +2,11 @@
int main()
{
Zombie* jean;
Zombie pierre("Pierre");
jean = new Zombie("jean");
jean->announce();
Zombie* jean = newZombie("jean");
jean->announe();
delete jean;
randomChump("francois");
Zombie no_name;
no_name.announe();
return 0;
}

View File

@ -2,8 +2,5 @@
Zombie* newZombie(std::string name)
{
Zombie* zombie;
zombie = new Zombie(name);
return (zombie);
return new Zombie(name);
}

View File

@ -1,8 +1,8 @@
#include "Zombie.hpp"
#include <string>
void randomChump(std::string name)
{
Zombie zombie(name);
zombie.announce();
zombie.announe();
}