I'm trying to create a dynamic spell system for a game I'm developing: spells should consist of an archetype, e.g. area of effect and an effect, e.g. heal.
I have following (simplified) code:
class SpellEffect {
public:
virtual void heal(int magnitude);
}
class SpellArchetype {
public:
virtual void applyToArea(int sizeOfArea, void (*func)(int));
}
class Spell {
SpellEffect effect;
SpellArchetype archetype;
int sizeOfArea;
int magnitude;
public:
void cast() {
archetype.applyToArea(sizeOfArea, &effect.heal);
}
}
However, since heal()
is a member function this does not work.
I also have trouble passing the argument magnitude
to the heal()
function.
I found this question and the answer seems helpful. Yet it has been a while since I last used C++ and I can't figure out how to make it work in my case since the this
is different.
Can someone please help me out?