More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Enviro++
更好教育论坛
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post Go to first unread
hong  
#1 Posted : Wednesday, 26 August 2009 12:32:49 AM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 523

Run Time Type Information (RTTI) in C++

Why RTTI?
Up-casting (treating sub-class as base class ) works fine, for example,
Code:
Animal * animal = new Dog();

However, down-casting might not be safe as correctness cannot be determined by the C++ compiler. See the following example.
Code:
Dog * dog = (Dog*) animal;

So we need RTTI to support both up-casting and down-casting.

Mechanisms for RTTI
1. dynamic_cast operator
2. typeid operator and type_info class

See details of dynamic_cast operator here.

RTTI typeid operator
- Obtains type info of an object/expression which is a reference to a standard library type called type_info.
- Usage: typeid( object) - The usage is similar to "sizeof".
- To get the name of the type, use typeid(object).name().

Edited by user Thursday, 4 July 2013 9:04:30 AM(UTC)  | Reason: Not specified

Sponsor
Rss Feed  Atom Feed
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.