[Enterprise Extensions only]

C++ value type library, runtime type information

Some of the classes in the WebSphere value type library contain methods that accept instances of a superclass. For such cases, the library use a C++ dynamic_cast to determine the type of the passed object; for example:

CORBA::Boolean equals(CORBA::ValueBase& arg0)
 {
    ...
	 OBV_java::lang::Integer*  argInteger = dynamic_cast<OBV_java::lang::Integer*>(& arg0) ;
	 ...
  }

This functionality allows you to perform type inquiries just as you would in Java using the "instance of" operator.

Note: However, for this code to work, a polymorphic hierarchy must exist (that is, at least one virtual function must be implemented in the class hierarchy).

Another possible approach is to use the "typeid()" operator of the type_info class; for example:

#include <typeinfo>
#include <iostream>
using namespace std;
class Test1 { __ };
class Test2 : Test1 {_..};
void main(void)
{
Test2* ptr = new Test2();
cout << typeid(*ptr).name() << endl; //yields the string "class Test2"
}

Depending on the compiler that is used, you must enable certain options in order for this functionality to work properly. For example, for MSVC++ the /GR option must be added to the compiler settings.