/ CPP_Modules / CPP_Module_04 / ex00 / Animal.cpp
Animal.cpp
 1  /* ************************************************************************** */
 2  /*                                                                            */
 3  /*                                                        :::      ::::::::   */
 4  /*   Animal.cpp                                         :+:      :+:    :+:   */
 5  /*                                                    +:+ +:+         +:+     */
 6  /*   By: gychoi <gychoi@student.42seoul.kr>         +#+  +:+       +#+        */
 7  /*                                                +#+#+#+#+#+   +#+           */
 8  /*   Created: 2023/08/15 16:02:27 by gychoi            #+#    #+#             */
 9  /*   Updated: 2023/08/16 21:52:22 by gychoi           ###   ########.fr       */
10  /*                                                                            */
11  /* ************************************************************************** */
12  
13  #include "Animal.hpp"
14  #include <iostream>
15  
16  /******************************
17   * Constructor and Destructor *
18   ******************************/
19  
20  Animal::Animal(void) : type("Animal")
21  {
22  	std::cout << "[Animal] : Default constructor called" << std::endl;
23  }
24  
25  Animal::~Animal(void)
26  {
27  	std::cout << "[Animal] : Destructor called" << std::endl;
28  }
29  
30  Animal::Animal(Animal const& target)
31  {
32  	std::cout << "[Animal] : Copy constructor called" << std::endl;
33  	if (this != &target)
34  		*this = target;
35  }
36  
37  Animal&	Animal::operator=(Animal const& target)
38  {
39  	std::cout << "[Animal] : Copy assignment operator called" << std::endl;
40  	if (this != &target)
41  		this->type = target.type;
42  	return *this;
43  }
44  
45  /******************************
46   *      Getter  function      *
47   ******************************/
48  
49  std::string	Animal::getType(void) const
50  {
51  	return this->type;
52  }
53  
54  /******************************
55   *   Public Member function   *
56   ******************************/
57  
58  void	Animal::makeSound(void) const
59  {
60  	std::cout << "[" << getType() << "] : **Incomprehensible roars of countless animals**" << std::endl;
61  }