A Simple Example
- Take a look at SpellT.h and SpellT.cpp
- I would like to extend a class that we don't have access to.
- In this case I want to create a DoubleSpell class.
- It just doubles the inpact of the spell.
- THIS IS SOMETHING YOU CAN DO, but it is not the correct way to do things in the end.
- This is for a case where we don't have access to source code for the class.
- Note, that the building of DoubleSpellT does not require SpellT to know anything about the DoubleSpellT
- DoubleSpellT does some strange things
- The way it is implmeneted, the constructor, GetSpellName and AddEffect in the base class are hidden by the new functions.
- If we could alter SpellT we could do something better
- We can still call the hidden functions
-
SpellT::function()
to call the base class.
- Note in the spell test, UseSpell can take a double,
- But it does not behave properly.
- This is called slicing
- "From the persepective of other code, an object belongs to its defined class as well as to any base classes."
- "From the perspective of a derived class, all
public
and protected
data members and methods from the base class are available."