I want to use 2 derived classes' methods acting on objects of these classes

I have a base class Creature. I made method attack(Creature &defender). Then I made 2 derived classes: Monster and Human. They need to have attack(Creature &defender) method wotking against each other. But as you know we cant put method working with class before class description. What is the best way to solve this situation, using objects?

25th Nov 2019, 8:21 AM
Арсений Горбунов
Арсений Горбунов - avatar
1 Answer
I don't understand your problem. In Java you would write something like this: public class Creature { private int xp; public void attack (Creature c){ c.xp--; if (c.xp <= 0){ //creature is dead } } } In C# it should be similar.
25th Nov 2019, 2:13 PM
Denise Roßberg
Denise Roßberg - avatar