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