+ 3

I need some assistance, please ! :(

Hi, my name is Josh and I need help with my code :'( Sorry to bother you guys, I've started to get hands on codding a game with my lack of knowledge and encountered some errors, the code below is an adaptation that I made from the Polymorphism course... I'll try to explain what I want to do... I want to make a function that gets the current weapon that I am using and prints it to the screen, I want to add the stats of the weapon to the base stats of a hero, Sorry, I know my code is bad... bare in mind that I am still learning and for me, the course is a little confusing, but I am trying really hard to learn, I am currently reading the book: C++ Primer 5th Edition to get a better understanding of the language... I am thanking you guys already for the help along the courses! https://code.sololearn.com/cK1T5bfUm47b UPDATED

19th Sep 2018, 1:23 AM
Marcos Dias (Ghosterrify)
Marcos Dias (Ghosterrify) - avatar
2 Respostas
+ 1
Maybe you can use composition. You can make an object of a class whitin the class Example: Class weapon {} Class shotgun : public weapon { int damage; } Class ninja { Protected: Weapon shotgun = new shotgun(); Public: Weapon printweapon() { return shotgun; } } Hope you understand(this code might not be valid)
20th Sep 2018, 11:02 AM
CodeMStr
CodeMStr - avatar
+ 1
Niek Aukes Thanks for the help, now I just gotta find a way to sum the weapon stats with the Ninja base stats, your concept seems way better than mine, thanks again!
20th Sep 2018, 2:22 PM
Marcos Dias (Ghosterrify)
Marcos Dias (Ghosterrify) - avatar