CPP04 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
Animal.cpp
[詳解]
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* Animal.cpp :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/05/20 16:24:52 by kamitsui #+# #+# */
9/* Updated: 2025/05/20 18:24:08 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
22#include "Animal.hpp"
23
29Animal::Animal() : type("Generic Animal") { std::cout << "Animal default constructor called" << std::endl; }
30
37Animal::Animal(const Animal &other) : type(other.type) { std::cout << "Animal copy constructor called" << std::endl; }
38
48 std::cout << "Animal copy assignment operator called" << std::endl;
49 if (this != &other) {
50 this->type = other.type;
51 }
52 return *this;
53}
54
59Animal::~Animal() { std::cout << "Animal destructor called" << std::endl; }
60
66void Animal::makeSound() const { std::cout << "Generic animal sound" << std::endl; }
67
72const std::string &Animal::getType() const { return this->type; }
The Animal class represents a generic animal.
Definition Animal.hpp:37
Animal()
Default constructor for Animal. Initializes the type to "Generic Animal". Displays a construction mes...
Definition Animal.cpp:29
const std::string & getType() const
Gets the type of the animal.
Definition Animal.cpp:72
virtual ~Animal()
Destructor for Animal. Displays a destruction message.
Definition Animal.cpp:59
virtual void makeSound() const
Makes a generic animal sound. This implementation is for the base Animal class. Derived classes are e...
Definition Animal.cpp:66
Animal & operator=(const Animal &other)
Copy assignment operator for Animal. Assigns the type from the other Animal object....
Definition Animal.cpp:47
std::string type
Definition Animal.hpp:39
T endl(T... args)
Declares the abstract Animal base class.