From: Michael Hope <michaelh@ju...> - 2001-01-29 21:46:45
Here's my two cents on inheritance in C:
1. Dont cast down to the base class, take the address of the base
instead. ie instead of
this removes the typecast so you get a little more type checking.
2. Consider adding an inheritance list somewhere to the classes. You can
then implement a function that given the expected type and a class will
walk the inheritance list and check if the cast is valid. I've seen it
used with a macro instead of the cast operator ie:
where base_type is the descriptor (id, pointer, whatever) and teh CAST
macro turns into a call to the walker during debug sessions, or a real
cast at release.