This is the type returned by the typeid operator. It can be used to compare the type of objects or to retrieve the name of a type.
typeid can be applied directly to types, in which case it returns its information; Or to objects, in which case it returns information on the type of the object.
When typeid is applied to a dereferenced pointer to an object of a polymorphic class type (a class declaring or inheriting a virtual function), it considers its dynamic type (i.e., the type of the most derived object). This requires the RTTI (Run-time type information) to be available.
When typeid is applied to a dereferenced null pointer a bad_typeid exception is thrown.
It is declared as:
| 1 2 3 4 5 6 7 8 9 10 11 |
|
Members
- operator==
operator!= - Comparison operators. They return whether the two types describe the same type.
A derived type is not considered the same type as any of its base classes.
- before
- Returns true if the type precedes the type of rhs in the collation order.
The collation order is just an internal order kept by a particular implementation and is not necessarily related to inheritance relations or declaring order. - name
- Returns a null-terminated character sequence with a human-readable name for the type.
- copy constructor and copy operator
- These are private, preventing type_info values from being copiable.
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
Possible output:
int is: int i is: int pi is: int * *pi is: int derived is: struct Derived *pbase is: struct Base same type? false polyderived is: struct Poly_Derived *ppolybase is: struct Poly_Derived same type? true |
See also
| bad_typeid | Exception thrown on typeid of null pointer (class) |
