I have multiple classes deriving from one base class with a polymorphic method that accepts the enum type declared in the base class. I repeat the enum in the subclasses so that each subclass only accepts its own specific group of values:
class Character {
enum Actions {
}
func performAction(action: Actions) {
// Functions to be performed by all subclasses
}
}
class Warrior: Character {
enum Actions {
case Attack, Block, Charge
}
override func performAction(action: Actions) {
// Add subclass-specific behavior
}
}
class Wizard: Character {
enum Actions {
case Attack, CastSpell, Run
}
override func performAction(action: Actions) {
// Add subclass-specific behavior
}
}
This of course doesn't work and I get
'Actions' is ambiguous for type lookup in this context.
I can't delete the enum in the base class because then I get an undeclared type error for the method. I have a strong feeling I'm going about this all wrong and trying to reinvent the wheel. Can someone point me in the right direction? Thank you.