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