d04 check leaks and error ok

This commit is contained in:
hugogogo
2022-03-14 18:18:45 +01:00
parent aa6f1c9928
commit 277f92ac93
21 changed files with 22 additions and 307 deletions

View File

@@ -9,10 +9,6 @@ NAME = pure
#TYPE = c
TYPE = cpp
ifndef TYPE
echo hello
endif
ifeq "$(TYPE)" "c"
CC = c
EXT = c
@@ -74,6 +70,9 @@ $(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
$(NAME): $(OBJS)
$(CC) $(OBJS) -o $@ $(LIBS)
leaks: $(NAME)
valgrind --leak-check=full --show-leak-kinds=all ./$(NAME)
clean:
$(RM_OBJS)

Binary file not shown.

View File

@@ -17,31 +17,31 @@ int main() {
Animal* j = new Cat("I am just a cat");
std::cout << std::endl;
std::cout << "cat i : ";
std::cout << B_BLUE "cat i : " RESET;
i->getBrain()->printIdea(0);
std::cout << "cat j : ";
std::cout << B_BLUE "cat j : " RESET;
j->getBrain()->printIdea(0);
std::cout << "\n*i = *j\n";
std::cout << "\n" B_BLUE "*i = *j" RESET "\n";
*i = *j;
std::cout << "cat i : ";
std::cout << B_BLUE "cat i : " RESET;
i->getBrain()->printIdea(0);
std::cout << "cat j : ";
std::cout << B_BLUE "cat j : " RESET;
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");;
std::cout << "cat i : ";
std::cout << B_BLUE "cat i : " RESET;
i->getBrain()->printIdea(0);
std::cout << "cat j : ";
std::cout << B_BLUE "cat j : " RESET;
j->getBrain()->printIdea(0);
std::cout << std::endl;
std::cout << "delete i\n";
std::cout << B_BLUE "delete i" RESET "\n";
delete i;
std::cout << "delete j\n";
std::cout << B_BLUE "delete j" RESET "\n";
delete j;
}

Binary file not shown.

View File

@@ -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;
}