C++ Programming/Programming Languages/C++/Code/Keywords/typeid


 * Syntax:

The  operator is used to determine the class of an object at runtime. It returns a reference to a  object, which exists until the end of the program, that describes the "object". If the "object" is a dereferenced null pointer, then the operation will throw a  exception.

Objects of class  are derived from , and thrown by   and others.

The use of  is often preferred over   in situations where just the class information is needed, because , applied on a type or non de-referenced value is a constant-time procedure, whereas  must traverse the class derivation lattice of its argument at runtime. However, you should never rely on the exact content, like for example returned by, as this is implementation specific with respect to the compile.

It is generally only useful to use  on the dereference of a pointer or reference (i.e.   or  ) to an object of polymorphic class type (a class with at least one virtual member function). This is because these are the only expressions that are associated with run-time type information. The type of any other expression is statically known at compile time.

Output (exact output varies by system):
 * Example