Rank: Administration
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 RTTI1. 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
|
|
|
|
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.