CPP04 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
Cat.cpp
[詳解]
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* Cat.cpp :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/05/20 16:26:14 by kamitsui #+# #+# */
9/* Updated: 2025/06/03 23:31:36 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
22#include "Cat.hpp"
23
30Cat::Cat() : Animal() {
31 this->type = "Cat";
32 this->brain = new Brain();
33 std::cout << "Cat default constructor called" << std::endl;
34}
35
43Cat::Cat(const Cat &other) : Animal(other) {
44 std::cout << "Cat copy constructor called" << std::endl;
45 this->brain = new Brain(*(other.brain)); // Deep copy of Brain
46}
47
53Cat::~Cat() {
54 delete this->brain;
55 std::cout << "Cat destructor called" << std::endl;
56}
57
63void Cat::swap(Cat &other) { std::swap(this->brain, other.brain); }
64
71Cat &Cat::operator=(const Cat &other) {
72 std::cout << "Cat copy assignment operator called (copy-and-swap)" << std::endl;
73 Cat temp(other);
74 this->swap(temp);
75 return *this;
76}
77
82void Cat::makeSound() const { std::cout << "Meow!" << std::endl; }
83
88void Cat::meow() const { std::cout << "Purrrr meow!" << std::endl; }
89
94Brain *Cat::getBrain() const { return this->brain; }
The Animal class represents a generic animal.
Definition Animal.hpp:37
Represents the brain of an animal, holding a collection of ideas.
Definition Brain.hpp:37
The Cat class represents a feline animal.
Definition Cat.hpp:33
void meow() const
Makes a specific purring and meowing sound for a Cat. This is a Cat-specific method.
Definition Cat.cpp:92
virtual void makeSound() const
Makes the characteristic sound of a cat ("Meow!"). This function overrides the virtual makeSound() fr...
Definition Cat.cpp:65
Brain * getBrain() const
Gets a pointer to the Cat's Brain object.
Definition Cat.cpp:98
Cat & operator=(const Cat &other)
Copy assignment operator for Cat. (Copy And Swap Idiom) Displays a specific copy assignment message.
Definition Cat.cpp:53
virtual ~Cat()
Destructor for Cat. Displays a specific destruction message.
Definition Cat.cpp:45
Cat()
Default constructor for Cat. Calls the Animal base class constructor and sets the type to "Cat"....
Definition Cat.cpp:28
T endl(T... args)
Declares the Cat class.
T swap(T... args)