/* 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 */
/* */
/* ************************************************************************** */
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;
}
/* 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;
+}
/* 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 */
/* */
/* ************************************************************************** */
public:
HumanB(const std::string &name);
void attack(void) const;
- void setWeapon(Weapon *weapon);
+ void setWeapon(Weapon &weapon);
private:
Weapon* weapon;
std::string name;
/* 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()
{
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;
}