More Group Sites
School Rankings
Jobless Net
Better Home
Enviro++


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest Search | Active Topics | Members | Log In | Register

Run Time Type Information (RTTI) in C++ Options · View
hong
Posted: Wednesday, August 26, 2009 4:32:49 AM

Rank: Administration
Groups: Administration

Joined: 11/23/2008
Posts: 335
Points: 711
Location: Australia
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().

Sponsor
Posted: Wednesday, August 26, 2009 4:32:49 AM
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.

Main Forum RSS : RSS

ASPNET Theme created by Boskone (Dan Ferguson)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.
This page was generated in 0.049 seconds.