Lecture15

Lecture15 - When polymorphism is not appropriate: Extending...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CS11600: Introduction to Computer Programming (C++) Lecture 15 Svetlozar Nestorov University of Chicago 2/26/2003 Svetlozar Nestorov, CS 116: Intro to Programming II 2 Outline ± Abstract base classes ± Run-time type identification (RTTI) ± Applications of RTTI ± Dynamic casting 2/26/2003 Svetlozar Nestorov, CS 116: Intro to Programming II 3 Abstract Base Class ± An abstract base class is never instantiated • often sits at the top of object hierarchy. ± Pure virtual functions virtual void fun() = 0; • No implementation, derived classes must override it. 2/26/2003 Svetlozar Nestorov, CS 116: Intro to Programming II 4 Run-Time Type Identification ± RTTI: figure out the type of an object at run-time. ± Why? Polymorphism solves the problem? •No t a lways . ± Several derived classes from the same base have different member functions.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the 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

This note was uploaded on 10/10/2009 for the course CS 11600 taught by Professor Svetlozarnestorov during the Winter '03 term at UChicago.

Page1 / 2

Lecture15 - When polymorphism is not appropriate: Extending...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online