summaryrefslogtreecommitdiff
path: root/ex03
diff options
context:
space:
mode:
Diffstat (limited to 'ex03')
-rw-r--r--ex03/HumanA.cpp5
-rw-r--r--ex03/HumanB.cpp19
-rw-r--r--ex03/HumanB.hpp4
-rw-r--r--ex03/main.cpp21
4 files changed, 34 insertions, 15 deletions
diff --git a/ex03/HumanA.cpp b/ex03/HumanA.cpp
index 84dec61..e7b6411 100644
--- a/ex03/HumanA.cpp
+++ b/ex03/HumanA.cpp
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/10 12:00:00 by dkaiser #+# #+# */
-/* Updated: 2025/02/10 12:51:24 by dkaiser ### ########.fr */
+/* Updated: 2025/02/10 12:59:46 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,5 +20,6 @@ HumanA::HumanA(const std::string &name, Weapon &weapon)
void HumanA::attack(void) const
{
- std::cout << name << "attacks with their " << weapon->getType() << std::endl;
+ std::cout << name << " attacks with their ";
+ std::cout << weapon->getType() << std::endl;
}
diff --git a/ex03/HumanB.cpp b/ex03/HumanB.cpp
index 4550c59..fad3f78 100644
--- a/ex03/HumanB.cpp
+++ b/ex03/HumanB.cpp
@@ -6,7 +6,24 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/10 12:00:11 by dkaiser #+# #+# */
-/* Updated: 2025/02/10 12:01:05 by dkaiser ### ########.fr */
+/* Updated: 2025/02/10 12:59:59 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
+#include "HumanB.hpp"
+#include <iostream>
+
+HumanB::HumanB(const std::string &name)
+ :name(name)
+{}
+
+void HumanB::attack(void) const
+{
+ std::cout << name << " attacks with their ";
+ std::cout << weapon->getType() << std::endl;
+}
+
+void HumanB::setWeapon(Weapon &weapon)
+{
+ this->weapon = &weapon;
+}
diff --git a/ex03/HumanB.hpp b/ex03/HumanB.hpp
index ce4edbd..c22b5c4 100644
--- a/ex03/HumanB.hpp
+++ b/ex03/HumanB.hpp
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/10 12:00:55 by dkaiser #+# #+# */
-/* Updated: 2025/02/10 12:29:43 by dkaiser ### ########.fr */
+/* Updated: 2025/02/10 12:55:00 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,7 +21,7 @@ class HumanB
public:
HumanB(const std::string &name);
void attack(void) const;
- void setWeapon(Weapon *weapon);
+ void setWeapon(Weapon &weapon);
private:
Weapon* weapon;
std::string name;
diff --git a/ex03/main.cpp b/ex03/main.cpp
index e53d3a0..de69c15 100644
--- a/ex03/main.cpp
+++ b/ex03/main.cpp
@@ -6,12 +6,13 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/10 11:58:15 by dkaiser #+# #+# */
-/* Updated: 2025/02/10 12:48:13 by dkaiser ### ########.fr */
+/* Updated: 2025/02/10 12:58:13 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "Weapon.hpp"
#include "HumanA.hpp"
+#include "HumanB.hpp"
int main()
{
@@ -22,13 +23,13 @@ int main()
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;
+ {
+ 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;
}