Standard C++ does not possess aDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
type(...) operator. Type querying and deduction are instead handled by two distinct standard operators: decltype(...) for compile-time type deduction, and typeid(...) for Run-Time Type Information (RTTI) and static type identification.
decltype(...)
The decltype operator inspects the declared type of an entity or the type and value category of an expression. It is evaluated entirely at compile-time and does not execute the expression it evaluates.
Syntax:
- Unparenthesized id-expression or class member access: If the operand is an unparenthesized identifier or a member access expression (
obj.memberorptr->member),decltypeyields the exact declared type of the entity. - Parenthesized expression or other expressions: If the operand is an expression of type
T, the resulting type depends on the expression’s value category:- If the expression is an lvalue,
decltypeyieldsT&. - If the expression is an xvalue,
decltypeyieldsT&&. - If the expression is a prvalue,
decltypeyieldsT.
- If the expression is an lvalue,
typeid(...)
The typeid operator queries information about a type. The operator yields an lvalue of type const std::type_info (defined in the <typeinfo> header) that represents the type.
Syntax:
- Type Operand: If the operand is a type-id,
typeidevaluates at compile-time and yields theconst std::type_infofor that exact type. - Non-Polymorphic Expression Operand: If the operand is an expression whose static type is not a polymorphic class (a class with at least one virtual function),
typeidevaluates at compile-time. The expression is not executed. - Polymorphic Expression Operand: If the operand is a glvalue expression of a polymorphic class type,
typeidevaluates at run-time. It inspects the vtable to yield theconst std::type_infoof the most derived (dynamic) type of the object. - Null Pointer Dereference: If the operand is a dereferenced null pointer of a polymorphic class type (e.g.,
typeid(*ptr)whereptrevaluates to a null pointer value), the operator throws astd::bad_typeidexception. - CV-Qualifiers and References:
typeidstrips top-levelconstandvolatilequalifiers and ignores references before evaluation.typeid(T&)andtypeid(const T)both yield theconst std::type_infoforT.
Master C++ with Deep Grasping Methodology!Learn More





