<typeinfo>Include the standard header <typeinfo>
to define several types associated with the type-identification operator
typeid,
which yields information about both static and dynamic types.
namespace std {
class type_info;
class bad_cast;
class bad_typeid;
} // namespace std
bad_castclass bad_cast
: public exception
{ // reports an exception
};
The class describes an exception thrown to indicate that a dynamic cast expression, of the form:
dynamic_cast<type>(expression)
generated a null pointer to initialize a reference.
The value returned by
what()
is an implementation-defined
C string.
None of the member functions throw any exceptions.
bad_typeidclass bad_typeid
: public exception
{ // reports a bad typeid
};
The class describes an exception thrown to indicate that a
typeid operator encountered a
null pointer. The value returned by
what()
is an implementation-defined
C string.
None of the member functions throw any exceptions.
type_infoclass type_info {
public:
virtual ~type_info();
type_info(const type_info& right) = delete; [added with C++11]
type_info& operator=(const type_info& right) = delete; [added with C++11]
size_t hash_code() const; [added with C++11]
bool before(const type_info& right) const noexcept;
const char *name() const noexcept;
bool operator==(const type_info& right) const noexcept;
bool operator!=(const type_info& right) const noexcept;
};
The class describes type information generated within the program by the implementation. Objects of this class effectively store a pointer to a name for the type, and an encoded value suitable for comparing two types for equality or collating order. The names, encoded values, and collating order for types are all unspecified and may differ between program executions.
An expression of the form typeid Ty is the only way to
construct a (temporary) typeinfo object. The class has only
a private copy constructor. Since the assignment operator is also
private, you cannot copy or assign objects of class typeinfo
either.
type_info::beforebool before(const type_info& right) const noexcept;
The member function returns a nonzero value if *this
precedes right in the
collating order for types.
type_info::hash_codesize_t hash_code() const; [added with C++11]
The member function defines a
hash function, suitable for mapping values of type
typeinfo to a distribution of index values.
type_info::nameconst char *name() const noexcept;
The member function returns a C string which specifies the name of the type.
type_info::operator!=bool operator!=(const type_info& right) const noexcept;
The member operator returns !(*this
== right).
type_info::operator==bool operator==(const type_info& right) const noexcept;
The member operator returns a nonzero value if *this
and right represent the same type.
See also the Table of Contents and the Index.
Copyright © 1992-2013 by P.J. Plauger. All rights reserved.