CPP01 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
HumanB.cpp
[詳解]
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* HumanB.cpp :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/04/15 19:44:16 by kamitsui #+# #+# */
9/* Updated: 2025/04/23 01:25:59 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
18#include "HumanB.hpp"
19#include <iostream>
20
28HumanB::HumanB(std::string name) : name(name), weapon(NULL) {
29 std::cout << "HumanB '" << this->name << "' created." << std::endl;
30}
31
35HumanB::~HumanB() { std::cout << "HumanB '" << this->name << "' destroyed." << std::endl; }
36
43 this->weapon = &weapon;
44 std::cout << "HumanB '" << this->name << "' equips weapon '" << this->weapon->getType() << "'." << std::endl;
45}
46
53void HumanB::attack() const {
54 std::cout << this->name << " attacks with their ";
55 if (this->weapon) {
56 std::cout << this->weapon->getType() << std::endl;
57 } else {
58 std::cout << "bare hands" << std::endl;
59 }
60}
Declares the HumanB class.
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
ostream cout
HumanB(std::string name)
Constructor for the HumanB class.
Definition HumanB.cpp:28
void setWeapon(Weapon &weapon)
Sets the weapon for the HumanB.
Definition HumanB.cpp:42
void attack() const
Makes the HumanB attack.
Definition HumanB.cpp:53
~HumanB()
Destructor for the HumanB class.
Definition HumanB.cpp:35
Represents a Weapon with a specific type.
Definition Weapon.hpp:26
const std::string & getType() const
Gets the type of the weapon.
Definition Weapon.cpp:40