typeid operator

From cppreference.com
 
 
C++ language
General topics
Preprocessor
Comments
Keywords
ASCII chart
Escape sequences
History of C++
Flow control
Conditional execution statements
Iteration statements
Jump statements
Functions
function declaration
lambda function declaration
function template
inline specifier
exception specifications (deprecated)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
decltype specifier (C++11)
Specifiers
cv specifiers
storage duration specifiers
constexpr specifier (C++11)
auto specifier (C++11)
alignas specifier (C++11)
Literals
Expressions
alternative representations
Utilities
Types
typedef declaration
type alias declaration (C++11)
attributes (C++11)
Casts
implicit conversions
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-style and functional cast
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
class template
function template
template specialization
parameter packs (C++11)
Miscellaneous
Inline assembly
 

Queries information of a type.

Used where the actual type of a virtual base class must be known.

Contents

[edit] Syntax

typeid( type ) (1)
typeid( expression ) (2)

Header <typeinfo> must be included before using typeid operator.

Both versions return an object of type const std::type_info&.

[edit] Explanation

1) returns the type information about the type. The type will be definitely known compile time and no runtime overhead is caused.

2) expression is evaluated and type information corresponding to the resulting value is returned. If the expression in a virtual base class, the actual type of the class is queried dynamically with some runtime overhead. Otherwise the actual type is definitely known compile time and no runtime overhead is caused.

[edit] Keywords

typeid

[edit] Example