Chapter Contents |
Previous |
Next |
Pointer Qualification Conversions, Casts, and Run-Time Type Identification |
Beginning
with Release 6.50, the SAS/C C++ Development System supports Run-Time Type
Identification, or RTTI. RTTI enables the compiler to automatically generate
type information for objects checked at run time. The
RTTI
option must be specified for each compilation
unit to assure that class objects constructed with functions defined in the
unit have the information required for dynamic type identification by the
dynamic_cast
and
typeid()
operators. See Option Descriptions for more information
on the
RTTI
option. The
generated code will abort if the
dynamic_cast
or
typeid()
operators are applied to C++ class objects with virtual functions
which do not have RTTI information. This means it is generally unsafe to have
a program that uses
dynamic_cast
or
typeid()
but
does not generate RTTI information in all of its compilation units.
Compilation units that do not use
dynamic_cast
or
typeid()
can be compiled with the RTTI information. The resulting
object files
can be safely linked into progams that do not use RTTI. The C++ library is
compiled this way. Note that dynamic type identification applies only to C++
classes with virtual functions, so there is no compatibility issue with non-C++
code.
ISO C++ specifies that certain erroneous uses of
dynamic_cast
and
typeid()
cause a C++ exception to be thrown. If no exception handler
is available, the
terminate()
operator is called, which aborts the program by default. However,
a handler can be specified by
set_terminate()
to perform cleanup before terminating program execution.
See typeinfo.h Header File for more information on these operators.
As an extension to ISO C++, the run-time code for
RTTI will detect when
dynamic type information is requested for an object that was not compiled
with the
RTTI
option.
In such cases, an exception type of std::_ _non_ _rtti
is thrown.
The
typeid()
operator
returns a reference to a statically allocated object. The destructor should
never be called for this object. Calling
typeid()
for the same type in different compilation units may produce
references to different objects. Always use operator
==
or operator
!=
to test for type equality.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.