This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: ± When polymorphism is not appropriate: • Extending class libraries without modifying them. • Derived classes have member functions not appropriate for other derived classes. 2/26/2003 Svetlozar Nestorov, CS 116: Intro to Programming II 6 Dynamic Casting ± Language support for RTTI. ± dynamic_cast • Works with pointers and references of polymorphic classes. • Return if unsuccessful for pointers; raises exception for references. dynamic_cast<Room *>(loc) 2 2/26/2003 Svetlozar Nestorov, CS 116: Intro to Programming II 7 Typeid Operator ± Determines the type of an object. • Dynamically for expressions of polymorphic types • Statically otherwise. • A pointer, which points to an object of polymorphic type, is not polymorphic! ± Typeid is overloaded for: • Type, e.g. typeid(int) • Expression, e.g typeid(loc)...
View Full Document
- Winter '03
- Computer Programming, Run-Time Type Identification, Svetlozar Nestorov