diff options
| author | Dominik Kaiser | 2025-02-10 12:53:16 +0100 |
|---|---|---|
| committer | Dominik Kaiser | 2025-02-10 12:53:16 +0100 |
| commit | 57e945f03e37e741a527f07fdcd84307733635e7 (patch) | |
| tree | f6f1b67a329d1547217e421cc58ff6b867a45b2e | |
| parent | 4b7e380d5f718fe557ef6ae068d7896620bc24f2 (diff) | |
| download | cpp01-57e945f03e37e741a527f07fdcd84307733635e7.tar.gz cpp01-57e945f03e37e741a527f07fdcd84307733635e7.zip | |
Implement HumanA class
| -rw-r--r-- | ex03/HumanA.cpp | 14 | ||||
| -rw-r--r-- | ex03/HumanA.hpp | 6 | ||||
| -rw-r--r-- | ex03/Weapon.cpp | 5 | ||||
| -rw-r--r-- | ex03/Weapon.hpp | 4 | ||||
| -rw-r--r-- | ex03/main.cpp | 26 |
5 files changed, 44 insertions, 11 deletions
diff --git a/ex03/HumanA.cpp b/ex03/HumanA.cpp index 38d2076..84dec61 100644 --- a/ex03/HumanA.cpp +++ b/ex03/HumanA.cpp @@ -6,7 +6,19 @@ /* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/10 12:00:00 by dkaiser #+# #+# */ -/* Updated: 2025/02/10 12:00:02 by dkaiser ### ########.fr */ +/* Updated: 2025/02/10 12:51:24 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ +#include "HumanA.hpp" +#include <iostream> + +HumanA::HumanA(const std::string &name, Weapon &weapon) + :weapon(&weapon), + name(name) +{} + +void HumanA::attack(void) const +{ + std::cout << name << "attacks with their " << weapon->getType() << std::endl; +} diff --git a/ex03/HumanA.hpp b/ex03/HumanA.hpp index b373665..b127c67 100644 --- a/ex03/HumanA.hpp +++ b/ex03/HumanA.hpp @@ -6,7 +6,7 @@ /* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/10 11:59:28 by dkaiser #+# #+# */ -/* Updated: 2025/02/10 12:25:54 by dkaiser ### ########.fr */ +/* Updated: 2025/02/10 12:51:15 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,10 +19,10 @@ class HumanA { public: - HumanA(const std::string &name, const Weapon &weapon); + HumanA(const std::string &name, Weapon &weapon); void attack(void) const; private: - Weapon weapon; + Weapon* weapon; std::string name; }; diff --git a/ex03/Weapon.cpp b/ex03/Weapon.cpp index e9dde06..bed64b5 100644 --- a/ex03/Weapon.cpp +++ b/ex03/Weapon.cpp @@ -6,13 +6,14 @@ /* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/10 11:59:21 by dkaiser #+# #+# */ -/* Updated: 2025/02/10 12:11:07 by dkaiser ### ########.fr */ +/* Updated: 2025/02/10 12:45:10 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ #include "Weapon.hpp" -Weapon::Weapon(void) +Weapon::Weapon(const std::string &type) + :type(type) {} const std::string& Weapon::getType(void) const diff --git a/ex03/Weapon.hpp b/ex03/Weapon.hpp index 917b367..945644c 100644 --- a/ex03/Weapon.hpp +++ b/ex03/Weapon.hpp @@ -6,7 +6,7 @@ /* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/10 11:58:44 by dkaiser #+# #+# */ -/* Updated: 2025/02/10 12:09:57 by dkaiser ### ########.fr */ +/* Updated: 2025/02/10 12:45:20 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ class Weapon { public: - Weapon(void); + Weapon(const std::string &type); const std::string& getType(void) const; void setType(const std::string &type); private: diff --git a/ex03/main.cpp b/ex03/main.cpp index b2ae001..e53d3a0 100644 --- a/ex03/main.cpp +++ b/ex03/main.cpp @@ -6,9 +6,29 @@ /* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/10 11:58:15 by dkaiser #+# #+# */ -/* Updated: 2025/02/10 11:58:24 by dkaiser ### ########.fr */ +/* Updated: 2025/02/10 12:48:13 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ -int main(void) -{} +#include "Weapon.hpp" +#include "HumanA.hpp" + +int main() +{ + { + Weapon club = Weapon("crude spiked club"); + HumanA bob("Bob", club); + bob.attack(); + club.setType("some other type of club"); + bob.attack(); + } + // { + // Weapon club = Weapon("crude spiked club"); + // HumanB jim("Jim"); + // jim.setWeapon(club); + // jim.attack(); + // club.setType("some other type of club"); + // jim.attack(); + // } + // return 0; +} |
