--- /dev/null
+#include "HumanA.h"
+#include "Weapon.h"
+#include <string>
+#include <iostream>
+
+HumanA::HumanA(std::string name, Weapon &weapon): m_name(name), m_weapon(weapon)
+{
+}
+
+HumanA::~HumanA()
+{
+}
+
+void HumanA::attack(void)
+{
+ std::cout << m_name << " attacks with their " << m_weapon.getType() << '\n';
+}
--- /dev/null
+#ifndef HUMANA_H
+# define HUMANA_H
+
+#include "Weapon.h"
+#include <string>
+
+class HumanA
+{
+ private:
+ std::string m_name;
+ Weapon &m_weapon;
+
+ public:
+ HumanA(std::string name, Weapon &weapon);
+ ~HumanA();
+
+ void attack(void);
+};
+
+#endif // HUMANA_H
--- /dev/null
+#include "HumanB.h"
+#include "Weapon.h"
+#include <string>
+#include <iostream>
+
+HumanB::HumanB(std::string name, Weapon *weapon): m_name(name), m_weapon(weapon)
+{
+}
+
+HumanB::~HumanB()
+{
+}
+
+void HumanB::setWeapon(Weapon &weapon)
+{
+ m_weapon = &weapon;
+}
+
+void HumanB::attack(void)
+{
+ std::cout << m_name << " attacks with their " << m_weapon->getType() << '\n';
+}
--- /dev/null
+#ifndef HUMANB_H
+# define HUMANB_H
+
+#include "Weapon.h"
+#include <string>
+
+class HumanB
+{
+ private:
+ std::string m_name;
+ Weapon *m_weapon;
+
+ public:
+ HumanB(std::string name = "human", Weapon *weapon = NULL);
+ ~HumanB();
+
+ void setWeapon(Weapon &weapon);
+ void attack(void);
+};
+
+#endif // HUMANB_H
--- /dev/null
+#include "Weapon.h"
+#include <string>
+
+Weapon::Weapon(std::string type): m_type(type)
+{
+}
+
+Weapon::Weapon(const Weapon &weapon)
+{
+ *this = weapon;
+}
+
+Weapon::~Weapon()
+{
+}
+
+Weapon &Weapon::operator=(const Weapon &weapon)
+{
+ this->m_type = weapon.m_type;
+ return (*this);
+}
+
+const std::string &Weapon::getType(void)
+{
+ return (m_type);
+}
+
+void Weapon::setType(std::string type)
+{
+ m_type = type;
+}
--- /dev/null
+#ifndef WEAPON_H
+# define WEAPON_H
+
+# include <string>
+
+class Weapon
+{
+ private:
+ std::string m_type;
+
+ public:
+ Weapon(std::string type = "none");
+ Weapon(const Weapon &weapon);
+ ~Weapon();
+
+ Weapon &operator=(const Weapon &weapon);
+ const std::string &getType(void);
+ void setType(std::string type);
+};
+
+#endif // WEAPON_H
--- /dev/null
+#include "HumanA.h"
+#include "HumanB.h"
+#include "Weapon.h"
+
+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;
+}