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++ 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 = ex00
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

View File

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

View File

@ -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(const std::string& name);
~Zombie(); ~Zombie();
void announce(void) const; Zombie& operator=(const Zombie& src);
void setName(std::string name);
void announe(void);
}; };
Zombie* newZombie(std::string name);
void randomChump(std::string name); void randomChump(std::string name);
Zombie* newZombie(std::string name);

View File

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

View File

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

View File

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