Run Time Type Identification (RTTI)
What is RTTI
Given a parent class pointer or reference to an instance of one of the sub-classes this process
determines the sub-class type.
Normally you would not need to do this because the proper use of virtual functions will insure
that the correct sub-class function is called. But, there are some situations in which you need
to obtain this information.
Why would you need RTTI information in a program?
-
A particular sub-class type may have a special function that must be called.
-
Adding a function needed by only one sub-class type may not be practical.
-
A particular sub-class type may be derived from a parent class that you have no control over.
-
Using RTTI may solve efficiency problems.
Demonstration code for doing RTTI in both C++ and in Java is available in the Code Vault