<s>
In	O
computer	O
programming	O
,	O
run-time	B-Application
type	I-Application
information	I-Application
or	O
run-time	O
type	O
identification	O
(	O
RTTI	B-Application
)	O
is	O
a	O
feature	O
of	O
some	O
programming	O
languages	O
(	O
such	O
as	O
C++	B-Language
,	O
Object	B-Language
Pascal	I-Language
,	O
and	O
Ada	B-Language
)	O
that	O
exposes	O
information	O
about	O
an	O
object	O
's	O
data	O
type	O
at	B-Library
runtime	I-Library
.	O
</s>
<s>
Run-time	B-Application
type	I-Application
information	I-Application
may	O
be	O
available	O
for	O
all	O
types	O
or	O
only	O
to	O
types	O
that	O
explicitly	O
have	O
it	O
(	O
as	O
is	O
the	O
case	O
with	O
Ada	B-Language
)	O
.	O
</s>
<s>
Run-time	B-Application
type	I-Application
information	I-Application
is	O
a	O
specialization	O
of	O
a	O
more	O
general	O
concept	O
called	O
type	B-Application
introspection	I-Application
.	O
</s>
<s>
In	O
the	O
original	O
C++	B-Language
design	O
,	O
Bjarne	O
Stroustrup	O
did	O
not	O
include	O
run-time	B-Application
type	I-Application
information	I-Application
,	O
because	O
he	O
thought	O
this	O
mechanism	O
was	O
often	O
misused	O
.	O
</s>
<s>
In	O
C++	B-Language
,	O
RTTI	B-Application
can	O
be	O
used	O
to	O
do	O
safe	O
typecasts	O
,	O
using	O
the	O
dynamic_castxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
operator	O
,	O
and	O
to	O
manipulate	O
type	O
information	O
at	B-Library
runtime	I-Library
,	O
using	O
the	O
typeid	O
operator	O
and	O
std::type_info	O
class	O
.	O
</s>
<s>
In	O
Object	B-Language
Pascal	I-Language
,	O
RTTI	B-Application
can	O
be	O
used	O
to	O
perform	O
safe	O
type	O
casts	O
with	O
the	O
as	O
operator	O
,	O
test	O
the	O
class	O
to	O
which	O
an	O
object	O
belongs	O
with	O
the	O
is	O
operator	O
,	O
and	O
manipulate	O
type	O
information	O
at	O
run	B-Library
time	I-Library
with	O
classes	O
contained	O
in	O
the	O
RTTI	B-Application
unit	O
(	O
i.e.	O
</s>
<s>
In	O
Ada	B-Language
,	O
objects	O
of	O
tagged	O
types	O
also	O
store	O
a	O
type	O
tag	O
,	O
which	O
permits	O
the	O
identification	O
of	O
the	O
type	O
of	O
these	O
object	O
at	B-Library
runtime	I-Library
.	O
</s>
<s>
The	O
in	O
operator	O
can	O
be	O
used	O
to	O
test	O
,	O
at	B-Library
runtime	I-Library
,	O
if	O
an	O
object	O
is	O
of	O
a	O
specific	O
type	O
and	O
may	O
be	O
safely	O
converted	O
to	O
it	O
.	O
</s>
<s>
RTTI	B-Application
is	O
available	O
only	O
for	O
classes	O
that	O
are	O
polymorphic	B-Application
,	O
which	O
means	O
they	O
have	O
at	O
least	O
one	O
virtual	B-Application
method	I-Application
.	O
</s>
<s>
Some	O
compilers	O
have	O
flags	O
to	O
disable	O
RTTI	B-Application
.	O
</s>
<s>
The	O
typeid	O
keyword	O
is	O
used	O
to	O
determine	O
the	O
class	O
of	O
an	O
object	O
at	O
run	B-Library
time	I-Library
.	O
</s>
<s>
It	O
returns	O
a	O
reference	B-Language
to	O
std::type_info	O
object	O
,	O
which	O
exists	O
until	O
the	O
end	O
of	O
the	O
program	O
.	O
</s>
<s>
The	O
use	O
of	O
typeid	O
,	O
in	O
a	O
non-polymorphic	O
context	O
,	O
is	O
often	O
preferred	O
over	O
dynamic_castxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1	O
in	O
situations	O
where	O
just	O
the	O
class	O
information	O
is	O
needed	O
,	O
because	O
typeid	O
is	O
always	O
a	O
constant-time	O
procedure	O
,	O
whereas	O
dynamic_cast	O
may	O
need	O
to	O
traverse	O
the	O
class	O
derivation	O
lattice	O
of	O
its	O
argument	O
at	B-Library
runtime	I-Library
.	O
</s>
<s>
Whether	O
an	O
exception	B-General_Concept
is	O
thrown	O
for	O
other	O
null	O
reference	B-Language
arguments	O
is	O
implementation-dependent	O
.	O
</s>
<s>
In	O
other	O
words	O
,	O
for	O
the	O
exception	B-General_Concept
to	O
be	O
guaranteed	O
,	O
the	O
expression	O
must	O
take	O
the	O
form	O
typeid( *p	O
)	O
where	O
p	O
is	O
any	O
expression	O
resulting	O
in	O
a	O
null	O
pointer	O
.	O
</s>
<s>
The	O
dynamic_cast	O
operator	O
in	O
C++	B-Language
is	O
used	O
for	O
downcasting	B-Application
a	O
reference	B-Language
or	O
pointer	O
to	O
a	O
more	O
specific	O
type	O
in	O
the	O
class	B-Application
hierarchy	I-Application
.	O
</s>
<s>
Unlike	O
the	O
static_cast	O
,	O
the	O
target	O
of	O
the	O
dynamic_cast	O
must	O
be	O
a	O
pointer	O
or	O
reference	B-Language
to	O
class	O
.	O
</s>
<s>
Unlike	O
static_cast	O
and	O
C-style	B-Language
typecast	O
(	O
where	O
type	O
check	O
is	O
made	O
during	O
compilation	O
)	O
,	O
a	O
type	O
safety	O
check	O
is	O
performed	O
at	B-Library
runtime	I-Library
.	O
</s>
<s>
If	O
the	O
types	O
are	O
not	O
compatible	O
,	O
an	O
exception	B-General_Concept
will	O
be	O
thrown	O
(	O
when	O
dealing	O
with	O
references	B-Language
)	O
or	O
a	O
null	O
pointer	O
will	O
be	O
returned	O
(	O
when	O
dealing	O
with	O
pointers	O
)	O
.	O
</s>
<s>
A	O
Java	B-Language
typecast	O
behaves	O
similarly	O
;	O
if	O
the	O
object	O
being	O
cast	O
is	O
not	O
actually	O
an	O
instance	O
of	O
the	O
target	O
type	O
,	O
and	O
cannot	O
be	O
converted	O
to	O
one	O
by	O
a	O
language-defined	O
method	O
,	O
an	O
instance	O
of	O
java.lang.ClassCastException	O
will	O
be	O
thrown	O
.	O
</s>
<s>
Exception	B-General_Concept
std::bad_cast	O
thrown	O
.	O
</s>
<s>
A	O
similar	O
version	O
of	O
MyFunction	O
can	O
be	O
written	O
with	O
pointers	O
instead	O
of	O
references	B-Language
:	O
</s>
<s>
In	O
Object	B-Language
Pascal	I-Language
,	O
the	O
operator	O
is	O
is	O
used	O
to	O
check	O
the	O
type	O
of	O
a	O
class	O
at	O
run	B-Library
time	I-Library
.	O
</s>
<s>
The	O
operator	O
as	O
is	O
used	O
when	O
an	O
object	O
needs	O
to	O
be	O
treated	O
at	O
run	B-Library
time	I-Library
as	O
if	O
it	O
belonged	O
to	O
an	O
ancestor	O
class	O
.	O
</s>
<s>
The	O
RTTI	B-Application
unit	O
is	O
used	O
to	O
manipulate	O
object	O
type	O
information	O
at	O
run	B-Library
time	I-Library
.	O
</s>
<s>
The	O
following	O
example	O
shows	O
the	O
use	O
of	O
the	O
RTTI	B-Application
module	O
to	O
obtain	O
information	O
about	O
the	O
class	O
to	O
which	O
an	O
object	O
belongs	O
,	O
creating	O
it	O
,	O
and	O
to	O
call	O
its	O
method	O
.	O
</s>
