We help IT Professionals succeed at work.

what is the C++ equivalent of JAVA instanceof ?

ndoung
ndoung asked
on
I have a pointer to a C++ base class object. I need to know what is the real class in order to do something.
In JAVA, we can use instanceof to check. I am looking for something equivalent in C++.
Comment
Watch Question

There is no an equivalence of Java instanceof in C++.
In C++ you should maybe check with dynamic_cast.
Some compilers allow you to compile with RTTI (run-time type information) embedded into the executable. See http://www.devx.com/getHelpOn/Article/10202/1954 for more info. I know Visual C++ disables RTTI by default (as maintaining RTTI causes performance degradation) but it can be enabled in the project options. I'm not sure if these extensions are part of the C++ standard or compiler-specific extensions.

Cheers,
   Chris