/* 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;
+}
/* 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 */
/* */
/* ************************************************************************** */
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;
};
/* 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
/* 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 */
/* */
/* ************************************************************************** */
class Weapon
{
public:
- Weapon(void);
+ Weapon(const std::string &type);
const std::string& getType(void) const;
void setType(const std::string &type);
private:
/* 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;
+}