summaryrefslogtreecommitdiff
path: root/ex03
diff options
context:
space:
mode:
Diffstat (limited to 'ex03')
-rw-r--r--ex03/HumanA.cpp14
-rw-r--r--ex03/HumanA.hpp6
-rw-r--r--ex03/Weapon.cpp5
-rw-r--r--ex03/Weapon.hpp4
-rw-r--r--ex03/main.cpp26
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;
+}