CPP01
1.0
読み取り中…
検索中…
一致する文字列を見つけられません
main.cpp
[詳解]
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* main.cpp :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2025/04/14 20:22:59 by kamitsui #+# #+# */
9
/* Updated: 2025/04/25 21:25:16 by kamitsui ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
18
#include "
Zombie.hpp
"
19
#include <
cstdlib
>
// For system("leaks...") on macOS
20
#include <
iostream
>
21
25
void
leak_check
(
void
) {
26
// Optional: Check for memory leaks (OS-dependent)
27
#ifdef __APPLE__
28
std::cout
<<
"\nChecking for memory leaks (macOS):"
<<
std::endl
;
29
system(
"leaks ./MoreBraiiiiiiinnnzzzZ"
);
// Replace a.out with your executable name
30
#elif __linux__
31
std::cout
<<
"\nChecking for memory leaks (Linux): Use valgrind (not in code)."
<<
std::endl
;
32
std::cout
<<
"Run: valgrind --leak-check=full ./MoreBraiiiiiiinnnzzzZ"
<<
std::endl
;
// Replace ./a.out
33
#endif
34
}
35
44
int
main
(
void
) {
45
int
hordeSize = 5;
46
std::string
zombieName =
"Braineater"
;
47
48
Zombie
*zombieGroup =
zombieHorde
(hordeSize, zombieName);
49
50
if
(zombieGroup != NULL) {
51
std::cout
<<
"Horde created!"
<<
std::endl
;
52
for
(
int
i = 0; i < hordeSize; ++i) {
53
zombieGroup[i].
announce
();
54
}
55
}
else
{
56
std::cerr
<<
"Failed to create zombie horde."
<<
std::endl
;
57
leak_check
();
58
return
1;
59
}
60
61
std::cout
<<
"Deleting the horde..."
<<
std::endl
;
62
delete
[] zombieGroup;
63
zombieGroup = NULL;
// Good practice to set pointer to NULL after deleting
64
65
std::cout
<<
"\nTesting with 0 zombies:"
<<
std::endl
;
66
Zombie
*emptyHorde =
zombieHorde
(0,
"None"
);
67
if
(emptyHorde == NULL) {
68
std::cout
<<
"Successfully handled 0 zombie horde."
<<
std::endl
;
69
leak_check
();
70
return
1;
71
}
72
73
leak_check
();
74
return
0;
75
}
iostream
cstdlib
std::endl
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
std::cerr
ostream cerr
std::cout
ostream cout
std::basic_string
Zombie
Represents a Zombie.
Definition
Zombie.hpp:30
Zombie::announce
void announce(void)
Announces the zombie.
Definition
Zombie.cpp:48
leak_check
void leak_check(void)
Checks for memory leaks (OS-dependent).
Definition
main.cpp:25
main
int main()
Main function of the program.
Definition
main.cpp:44
Zombie.hpp
Declares the Zombie class and the zombieHorde function.
zombieHorde
Zombie * zombieHorde(int N, std::string name)
Creates a horde of Zombies on the heap.
Definition
zombieHorde.cpp:35
ex01
main.cpp
構築:
1.9.8