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 23:27:17 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
21#include "Dog.hpp"
22
29 this->type = "Dog";
30 std::cout << "Dog default constructor called" << std::endl;
31}
32
39Dog::Dog(const Dog &other) : Animal(other) { std::cout << "Dog copy constructor called" << std::endl; }
40
45Dog::~Dog() { std::cout << "Dog destructor called" << std::endl; }
46
53Dog &Dog::operator=(const Dog &other) {
54 std::cout << "Dog copy assignment operator called" << std::endl;
55 if (this != &other) {
56 Animal::operator=(other);
57 }
58 return *this;
59}
60
65void Dog::makeSound() const { std::cout << "Woof!" << std::endl; }
The Animal class represents a generic animal.
Definition Animal.hpp:37
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
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
virtual ~Dog()
Destructor for Dog. Displays a specific destruction message.
Definition Dog.cpp:45
T endl(T... args)
Declares the Dog class.