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/23 01:33:46 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
18#include "Zombie.hpp"
19#include <cstdlib> // For system("leaks...") on macOS
20#include <iostream>
21
25void 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 ./BraiiiiiiinnnzzzZ"); // 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 ./BraiiiiiiinnnzzzZ" << std::endl; // Replace ./a.out
33#endif
34}
35
44int main() {
45 Zombie stackZombie("Stacky");
46 stackZombie.announce();
47
48 Zombie *heapZombie = newZombie("Heapy");
49 if (heapZombie == NULL) {
50 leak_check();
51 return 1;
52 }
53 heapZombie->announce();
54 delete heapZombie;
55
56 randomChump("Chumpy");
57
58 leak_check();
59 return 0;
60}
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
ostream cout
Represents a Zombie.
Definition Zombie.hpp:30
void announce(void)
Announces the zombie.
Definition Zombie.cpp:48
void leak_check(void)
Checks for memory leaks (OS-dependent).
Definition main.cpp:25
int main()
Main function of the program.
Definition main.cpp:44
Declares the Zombie class and the zombieHorde function.
Zombie * newZombie(std::string name)
Creates a new Zombie on the heap.
Definition newZombie.cpp:29
void randomChump(std::string name)
Creates a Zombie on the stack and makes it announce itself.