Cat.cpp
1 /* ************************************************************************** */ 2 /* */ 3 /* ::: :::::::: */ 4 /* Cat.cpp :+: :+: :+: */ 5 /* +:+ +:+ +:+ */ 6 /* By: gychoi <gychoi@student.42seoul.kr> +#+ +:+ +#+ */ 7 /* +#+#+#+#+#+ +#+ */ 8 /* Created: 2023/08/15 16:05:36 by gychoi #+# #+# */ 9 /* Updated: 2023/08/16 22:31:01 by gychoi ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 #include "Cat.hpp" 14 #include <iostream> 15 16 /****************************** 17 * Constructor and Destructor * 18 ******************************/ 19 20 Cat::Cat(void) 21 { 22 Animal::type = "Cat"; 23 std::cout << "[Cat] : Default constructor called" << std::endl; 24 } 25 26 Cat::~Cat(void) 27 { 28 std::cout << "[Cat] : Destructor called" << std::endl; 29 } 30 31 Cat::Cat(std::string name) : name(name) 32 { 33 Animal::type = "Cat"; 34 std::cout << "[Cat] : Parameterize constructor called" << std::endl; 35 } 36 37 Cat::Cat(Cat const& target) : Animal(target) 38 { 39 std::cout << "[Cat] : Copy constructor called" << std::endl; 40 if (this != &target) { 41 *this = target; 42 Animal::type = "Cat"; 43 } 44 } 45 46 Cat& Cat::operator=(Cat const& target) 47 { 48 std::cout << "[Cat] : Copy assignment operator called" << std::endl; 49 if (this != &target) { 50 this->name = target.name; 51 Animal::operator=(target); 52 } 53 return *this; 54 } 55 56 /****************************** 57 * Getter function * 58 ******************************/ 59 60 std::string Cat::getType(void) const 61 { 62 return this->type; 63 } 64 65 std::string Cat::getName(void) const 66 { 67 return this->name; 68 } 69 70 /****************************** 71 * Public Member function * 72 ******************************/ 73 74 void Cat::makeSound(void) const 75 { 76 std::cout << "[" << getType() << "] : Don't bark." << std::endl; 77 }