d04 check leaks and error ok
This commit is contained in:
@@ -12,7 +12,7 @@ Cat::Cat() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cat::Cat( Cat const & src ) {
|
Cat::Cat( Cat const & src ) : Animal(src) {
|
||||||
std::cout << COPLIEN_COLOR "Cat copy constructor" RESET "\n";
|
std::cout << COPLIEN_COLOR "Cat copy constructor" RESET "\n";
|
||||||
*this = src;
|
*this = src;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ Dog::Dog() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dog::Dog( Dog const & src ) {
|
Dog::Dog( Dog const & src ) : Animal(src) {
|
||||||
std::cout << COPLIEN_COLOR "Dog copy constructor" RESET "\n";
|
std::cout << COPLIEN_COLOR "Dog copy constructor" RESET "\n";
|
||||||
*this = src;
|
*this = src;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ $(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
|
|||||||
$(NAME): $(OBJS)
|
$(NAME): $(OBJS)
|
||||||
$(CC) $(OBJS) -o $@ $(LIBS)
|
$(CC) $(OBJS) -o $@ $(LIBS)
|
||||||
|
|
||||||
|
leaks: $(NAME)
|
||||||
|
valgrind --leak-check=full --show-leak-kinds=all ./$(NAME)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM_OBJS)
|
$(RM_OBJS)
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ WrongCat::WrongCat() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WrongCat::WrongCat( WrongCat const & src ) {
|
WrongCat::WrongCat( WrongCat const & src ) : WrongAnimal(src) {
|
||||||
std::cout << COPLIEN_COLOR "WrongCat copy constructor" RESET "\n";
|
std::cout << COPLIEN_COLOR "WrongCat copy constructor" RESET "\n";
|
||||||
*this = src;
|
*this = src;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ $(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
|
|||||||
$(NAME): $(OBJS)
|
$(NAME): $(OBJS)
|
||||||
$(CC) $(OBJS) -o $@ $(LIBS)
|
$(CC) $(OBJS) -o $@ $(LIBS)
|
||||||
|
|
||||||
|
leaks: $(NAME)
|
||||||
|
valgrind --leak-check=full --show-leak-kinds=all ./$(NAME)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM_OBJS)
|
$(RM_OBJS)
|
||||||
|
|
||||||
|
|||||||
BIN
d04/ex01/burn
BIN
d04/ex01/burn
Binary file not shown.
@@ -9,10 +9,6 @@ NAME = pure
|
|||||||
#TYPE = c
|
#TYPE = c
|
||||||
TYPE = cpp
|
TYPE = cpp
|
||||||
|
|
||||||
ifndef TYPE
|
|
||||||
echo hello
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq "$(TYPE)" "c"
|
ifeq "$(TYPE)" "c"
|
||||||
CC = c
|
CC = c
|
||||||
EXT = c
|
EXT = c
|
||||||
@@ -74,6 +70,9 @@ $(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
|
|||||||
$(NAME): $(OBJS)
|
$(NAME): $(OBJS)
|
||||||
$(CC) $(OBJS) -o $@ $(LIBS)
|
$(CC) $(OBJS) -o $@ $(LIBS)
|
||||||
|
|
||||||
|
leaks: $(NAME)
|
||||||
|
valgrind --leak-check=full --show-leak-kinds=all ./$(NAME)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM_OBJS)
|
$(RM_OBJS)
|
||||||
|
|
||||||
|
|||||||
BIN
d04/ex02/a.out
BIN
d04/ex02/a.out
Binary file not shown.
@@ -17,31 +17,31 @@ int main() {
|
|||||||
Animal* j = new Cat("I am just a cat");
|
Animal* j = new Cat("I am just a cat");
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
std::cout << "cat i : ";
|
std::cout << B_BLUE "cat i : " RESET;
|
||||||
i->getBrain()->printIdea(0);
|
i->getBrain()->printIdea(0);
|
||||||
std::cout << "cat j : ";
|
std::cout << B_BLUE "cat j : " RESET;
|
||||||
j->getBrain()->printIdea(0);
|
j->getBrain()->printIdea(0);
|
||||||
|
|
||||||
std::cout << "\n*i = *j\n";
|
std::cout << "\n" B_BLUE "*i = *j" RESET "\n";
|
||||||
*i = *j;
|
*i = *j;
|
||||||
|
|
||||||
std::cout << "cat i : ";
|
std::cout << B_BLUE "cat i : " RESET;
|
||||||
i->getBrain()->printIdea(0);
|
i->getBrain()->printIdea(0);
|
||||||
std::cout << "cat j : ";
|
std::cout << B_BLUE "cat j : " RESET;
|
||||||
j->getBrain()->printIdea(0);
|
j->getBrain()->printIdea(0);
|
||||||
|
|
||||||
std::cout << "\nj->getBrain->putIdea(\"I am not a cat\")\n";
|
std::cout << "\n" B_BLUE "j->getBrain->putIdea(\"I am not a cat\")" RESET "\n";
|
||||||
j->getBrain()->putIdea(0, "I am not a cat");;
|
j->getBrain()->putIdea(0, "I am not a cat");;
|
||||||
|
|
||||||
std::cout << "cat i : ";
|
std::cout << B_BLUE "cat i : " RESET;
|
||||||
i->getBrain()->printIdea(0);
|
i->getBrain()->printIdea(0);
|
||||||
std::cout << "cat j : ";
|
std::cout << B_BLUE "cat j : " RESET;
|
||||||
j->getBrain()->printIdea(0);
|
j->getBrain()->printIdea(0);
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
std::cout << "delete i\n";
|
std::cout << B_BLUE "delete i" RESET "\n";
|
||||||
delete i;
|
delete i;
|
||||||
std::cout << "delete j\n";
|
std::cout << B_BLUE "delete j" RESET "\n";
|
||||||
delete j;
|
delete j;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
BIN
d04/ex02/pure
BIN
d04/ex02/pure
Binary file not shown.
@@ -1,38 +0,0 @@
|
|||||||
# include <iostream>
|
|
||||||
# include <string>
|
|
||||||
|
|
||||||
class Animal {
|
|
||||||
public:
|
|
||||||
virtual Animal & operator=( Animal const & rhs ) {
|
|
||||||
std::cout << "Animal operator=\n";
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class Cat : public Animal {
|
|
||||||
public:
|
|
||||||
Cat & operator=( Cat const & rhs ) {
|
|
||||||
Animal::operator=(rhs);
|
|
||||||
std::cout << "Cat operator=\n";
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
Cat & operator=( Animal const & rhs ) {
|
|
||||||
Animal::operator=(rhs);
|
|
||||||
std::cout << "Cat operator=\n";
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
void catSpeak() {std::cout << "I am a cat\n";}
|
|
||||||
};
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
Animal* i = new Cat();
|
|
||||||
Animal* j = new Cat();
|
|
||||||
|
|
||||||
i->catSpeak();
|
|
||||||
j->catSpeak();
|
|
||||||
*i = *j;
|
|
||||||
|
|
||||||
delete i;
|
|
||||||
delete j;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
|
||||||
# . name = value \ . += append to a variable #
|
|
||||||
# VARIABLES . value . != set result of command #
|
|
||||||
# . name is case sensitive . ?= set if not already set #
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
|
||||||
|
|
||||||
NAME = materia
|
|
||||||
|
|
||||||
#TYPE = c
|
|
||||||
TYPE = cpp
|
|
||||||
|
|
||||||
ifeq "$(TYPE)" "c"
|
|
||||||
CC = c
|
|
||||||
EXT = c
|
|
||||||
else ifeq "$(TYPE)" "cpp"
|
|
||||||
CC = c++
|
|
||||||
EXT = cpp
|
|
||||||
endif
|
|
||||||
|
|
||||||
CFLAGS = -Wall -Wextra -Werror $(INCLUDES)
|
|
||||||
ifeq "$(TYPE)" "cpp"
|
|
||||||
CFLAGS += -std=c++98
|
|
||||||
endif
|
|
||||||
|
|
||||||
VPATH = $(D_SRCS)
|
|
||||||
|
|
||||||
LIBS =
|
|
||||||
|
|
||||||
INCLUDES = -I$(D_HEADERS)
|
|
||||||
|
|
||||||
D_SRCS = srcs
|
|
||||||
SRCS = main.cpp \
|
|
||||||
Animal.cpp \
|
|
||||||
Dog.cpp \
|
|
||||||
Cat.cpp \
|
|
||||||
Brain.cpp
|
|
||||||
|
|
||||||
D_HEADERS = headers
|
|
||||||
HEADERS = Animal.hpp \
|
|
||||||
Dog.hpp \
|
|
||||||
Cat.hpp \
|
|
||||||
Brain.hpp
|
|
||||||
|
|
||||||
D_OBJS = builds
|
|
||||||
OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o)
|
|
||||||
|
|
||||||
ifeq "$(D_OBJS)" "."
|
|
||||||
RM_OBJS = rm -f $(OBJS)
|
|
||||||
else
|
|
||||||
RM_OBJS = rm -rf $(D_OBJS)
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
|
||||||
# . target: prerequisites . $@ : target #
|
|
||||||
# RULES . recipe . $< : 1st prerequisite #
|
|
||||||
# . recipe . $^ : all prerequisites #
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
|
||||||
|
|
||||||
all: $(NAME)
|
|
||||||
|
|
||||||
$(D_OBJS)/%.o: %.$(EXT) | $(D_OBJS)
|
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
|
||||||
|
|
||||||
$(D_OBJS):
|
|
||||||
mkdir $@
|
|
||||||
|
|
||||||
$(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
|
|
||||||
|
|
||||||
$(NAME): $(OBJS)
|
|
||||||
$(CC) $(OBJS) -o $@ $(LIBS)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(RM_OBJS)
|
|
||||||
|
|
||||||
fclean: clean
|
|
||||||
rm -f $(NAME)
|
|
||||||
|
|
||||||
re: fclean all
|
|
||||||
|
|
||||||
.PHONY : all clean fclean re
|
|
||||||
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#ifndef AMATERIA_HPP
|
|
||||||
# define AMATERIA_HPP
|
|
||||||
|
|
||||||
# include <iostream>
|
|
||||||
|
|
||||||
#include "ICharacter.hpp"
|
|
||||||
|
|
||||||
class AMateria {
|
|
||||||
|
|
||||||
public:
|
|
||||||
AMateria(std::string const & type);
|
|
||||||
virtual ~AMateria();
|
|
||||||
|
|
||||||
std::string const & getType() const; //Returns the materia type
|
|
||||||
|
|
||||||
virtual AMateria* clone() const = 0;
|
|
||||||
virtual void use(ICharacter& target);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
std::string _type;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#ifndef CHARACTER_HPP
|
|
||||||
# define CHARACTER_HPP
|
|
||||||
|
|
||||||
#include "ICharacter.hpp"
|
|
||||||
|
|
||||||
class Character : public ICharacter {
|
|
||||||
|
|
||||||
public:
|
|
||||||
Character();
|
|
||||||
Character( Character const & src );
|
|
||||||
~Character();
|
|
||||||
Character & operator=( Character const & rhs );
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#ifndef CURE_HPP
|
|
||||||
# define CURE_HPP
|
|
||||||
|
|
||||||
#include "AMateria.hpp"
|
|
||||||
|
|
||||||
class Cure : public AMateria {
|
|
||||||
|
|
||||||
public:
|
|
||||||
Cure();
|
|
||||||
Cure( Cure const & src );
|
|
||||||
~Cure();
|
|
||||||
Cure & operator=( Cure const & rhs );
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#ifndef ICE_HPP
|
|
||||||
# define ICE_HPP
|
|
||||||
|
|
||||||
class ICharacter {
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual ~ICharacter() {}
|
|
||||||
virtual std::string const & getName() const = 0;
|
|
||||||
virtual void equip(AMateria* m) = 0;
|
|
||||||
virtual void unequip(int idx) = 0;
|
|
||||||
virtual void use(int idx, ICharacter& target) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#ifndef ICE_HPP
|
|
||||||
# define ICE_HPP
|
|
||||||
|
|
||||||
#include "AMateria.hpp"
|
|
||||||
|
|
||||||
class Ice : public AMateria {
|
|
||||||
|
|
||||||
public:
|
|
||||||
Ice();
|
|
||||||
Ice( Ice const & src );
|
|
||||||
~Ice();
|
|
||||||
Ice & operator=( Ice const & rhs );
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
#include "AMateria.hpp"
|
|
||||||
#include "Ice.hpp"
|
|
||||||
#include "Cure.hpp"
|
|
||||||
#include "ICharacter"
|
|
||||||
#include "IMateriaSource"
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
|
|
||||||
IMateriaSource* src = new MateriaSource();
|
|
||||||
src->learnMateria(new Ice());
|
|
||||||
src->learnMateria(new Cure());
|
|
||||||
|
|
||||||
ICharacter* me = new Character("me");
|
|
||||||
|
|
||||||
AMateria* tmp;
|
|
||||||
tmp = src->createMateria("ice");
|
|
||||||
me->equip(tmp);
|
|
||||||
tmp = src->createMateria("cure");
|
|
||||||
me->equip(tmp);
|
|
||||||
|
|
||||||
ICharacter* bob = new Character("bob");
|
|
||||||
|
|
||||||
me->use(0, *bob);
|
|
||||||
me->use(1, *bob);
|
|
||||||
|
|
||||||
delete bob;
|
|
||||||
delete me;
|
|
||||||
delete src;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#include "AMateria.hpp"
|
|
||||||
|
|
||||||
AMateria::AMateria(std::string const & type) {
|
|
||||||
_type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string const & AMateria::getType() const {
|
|
||||||
return _type;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual AMateria * AMateria::clone() const {
|
|
||||||
AMateria clone = new AMateria;
|
|
||||||
return clone;
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#include "Cure.hpp"
|
|
||||||
|
|
||||||
Cure::Cure() : _type("cure") {}
|
|
||||||
|
|
||||||
Cure::Cure( Cure const & src ) {
|
|
||||||
*this = src
|
|
||||||
}
|
|
||||||
|
|
||||||
Cure & Cure::operator=( Cure const & rhs ) {
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Ice::use(ICharacter & target) {
|
|
||||||
std::cout << "* heals " << target.name << "’s wounds *"
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#include "Ice.hpp"
|
|
||||||
|
|
||||||
Ice::Ice() : _type("ice") {}
|
|
||||||
|
|
||||||
Ice::Ice( Ice const & src ) {
|
|
||||||
*this = src
|
|
||||||
}
|
|
||||||
|
|
||||||
Ice & Ice::operator=( Ice const & rhs ) {
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Ice::use(ICharacter & target) {
|
|
||||||
std::cout << "* shoots an ice bolt at " << target.name << " *"
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user