Home

typeinfo

Typeinfo refers to the runtime type information available for objects in certain programming languages, most commonly in C++. In C++, the mechanism is provided by the type_info class and the typeid operator, and it is part of the broader runtime type information (RTTI) feature set.

The typeid operator yields a reference to a std::type_info object that describes the static or dynamic type

A key aspect of typeinfo in C++ concerns polymorphism. If the expression is of a polymorphic class

Limitations include the implementation-defined nature of type names and potential portability concerns between compilers and libraries.

of
an
expression
or
object.
The
primary
means
of
accessing
this
information
is
typeid(x).name(),
which
returns
an
implementation-defined
string
representing
the
type.
The
actual
content
of
the
name
is
not
portable
across
compilers,
and
human-readable
names
may
require
demangling
on
some
platforms.
The
type_info
objects
can
be
compared
for
equality
or
inequality,
and
there
is
a
before()
function
to
impose
an
ordering
suitable
for
use
in
associative
containers.
(one
with
virtual
functions),
typeid
yields
the
dynamic
type
of
the
object
at
runtime.
If
the
expression
is
non-polymorphic,
typeid
yields
its
static
type.
This
distinction
makes
typeinfo
useful
for
debugging,
logging,
or
implementing
simple
type-based
dispatch,
but
it
should
not
be
relied
on
for
general
program
logic.
For
such
purposes,
dynamic_cast
can
also
be
used
to
test
or
convert
types
at
runtime.
RTTI
can
be
disabled
in
some
environments,
typically
via
compiler
flags,
which
would
render
typeid
and
related
features
unavailable.
typeinfo
is
primarily
a
C++
construct;
other
languages
implement
similar
concepts
under
different
names
and
APIs.
See
also
typeid,
std::type_info,
and
RTTI.