Some Clean UP
override
keyword
- This tells the compiler that you are overriding a method.
- This is NOT required, but it protects you.
- Assume we wish to add a range where the robot will be safe.
- I change the base class to include an integer i, the safety radius.
- But I forget to change it in the derived classes.
- So StatRobotT has
bool IsSafe() const;
- The compiler does not warn that this is a problem, but this builds a new IsSafe method.
- If the override keyword was a t the end, then the compiler would warn that this is probably a problem.
I added a new robot type, a hunted robot.
- I needed a new method, hunted robots squeek for some reason.
- How do I know I can call the squeek method?
- I could add a new variable to the base class, type to identify the type
- Then a nasty statement to set the type correctly in each derived class.
- Or I could use a dynamic_cast, or dynamic_pointer_cast.
- see this reference.
- Casting is dangerous
- Up Casting - base = new derived, OK
- Down Casting - derived = new base : bad
- In either case, use dynamic_cast
- And only with pointers.
Discuss hiding vs overriding.
Virtual Destructors.
Calling parent class methods ClassName::Function()
An example fltk widgets.