We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
You're supposed to call the non-generic spell's reveal function.
eg. revealFrostpower()
Notice that
Spell* spell;
When the new spell is not generic,
spell is a pointer to the base class "Spell",but it is pointing to the derived classes (fire,frost,etc...)
In order to use the reveal functions, you have to downcast the pointer.
You can use dynamic_cast for this.
In the case of generic spells, the pointer is actually pointing to the base class Spell. If you attempt to dynamic_cast this, it will fail and return a null ptr. If you then try to call the reveal functions from the null ptr, you'll get undefined behavior. So you have to write a check for if dynamic cast failed.
Magic Spells
You are viewing a single comment's thread. Return to all comments →
You're supposed to call the non-generic spell's reveal function. eg. revealFrostpower()
Notice that
Spell* spell;
When the new spell is not generic, spell is a pointer to the base class "Spell",but it is pointing to the derived classes (fire,frost,etc...) In order to use the reveal functions, you have to downcast the pointer. You can use dynamic_cast for this.
In the case of generic spells, the pointer is actually pointing to the base class Spell. If you attempt to dynamic_cast this, it will fail and return a null ptr. If you then try to call the reveal functions from the null ptr, you'll get undefined behavior. So you have to write a check for if dynamic cast failed.