Aptitude (12) ASP.NET (2) Automata (4) Browser (1) C (5) C# (1) C++ (10) Code (3) CSS (1) Data Structure (1) DATABASE (3) HTML (1) java (43) JSP (1) math (1) MySql (8) other (6) php (3) Servlet (3)

Saturday, 9 March 2013

RTTI

*Run Time Type Identification
*enables us to identify type an object during execution of program

*RTTI operators are runtime events for polymorphic classes and compile time events for all other types.
* two type of RTTI operators  are:
     1. typeid
      2. dynamic_cast

typeid
*typeid is an operator which returns refrence to object of type_info class
*Type_info class describers type of object

#include<type_info.h>
main()
{
int i,j;
float f;
char* p;
A a;
B b;

cout<<"type of i is "<<typeid(i).name();//int
cout<<"type of f is "<<typeid(i).name(); //float
cout<<"type of p is "<<typeid(i).name(); //char*
cout<<"type of a is "<<typeid(i).name();//class A
cout<<"type of b is "<<typeid(i).name(); //class B
}


casting operators
*dynamic_cast
*static_cast
*cont_cast
*reinterpret_cast

syntax:
cast_name<type>(expression)

 



No comments:

Post a Comment