0
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?
1 Respuesta
0
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.