main.cpp
1 /* ************************************************************************** */ 2 /* */ 3 /* ::: :::::::: */ 4 /* main.cpp :+: :+: :+: */ 5 /* +:+ +:+ +:+ */ 6 /* By: gychoi <gychoi@student.42seoul.kr> +#+ +:+ +#+ */ 7 /* +#+#+#+#+#+ +#+ */ 8 /* Created: 2023/07/24 22:45:48 by gychoi #+# #+# */ 9 /* Updated: 2023/07/25 22:26:08 by gychoi ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 #include "Zombie.hpp" 14 15 #ifdef LEAKS_CHECK 16 #include <cstdlib> 17 void check_leaks(void) 18 { 19 system("leaks --list -- zombieHorde"); 20 } 21 #define ATEXIT_CHECK() atexit(check_leaks) 22 #else 23 #define ATEXIT_CHECK() 24 #endif 25 26 int main(int argc, char* argv[]) 27 { 28 std::size_t N = 10; 29 30 ATEXIT_CHECK(); 31 if (argc == 2) 32 { 33 std::istringstream iss(argv[1]); 34 if (!(iss >> N) || N > static_cast<std::size_t>(std::numeric_limits<int>::max())) 35 { 36 std::cout << "Invalid number: " << argv[1] << std::endl; 37 return (1); 38 } 39 else if (!iss.eof()) { 40 std::cout << "Trailing characters after number: " << argv[1] << std::endl; 41 return (1); 42 } 43 } 44 Zombie* horde = zombieHorde(static_cast<int>(N), "ZombieHorde"); 45 46 for (std::size_t i = 0; i < N; i++) 47 horde[i].announce(); 48 delete[] horde; 49 return (0); 50 }