Cpp Notes

type_id

About term "type-id"

In C++, a "type-id" refers to the type specifier used to define a variable or object.

  • The Type-id specifies the type of the object being created with new.
  • It can be a built-in type (like int, double, etc.) or a user-defined type (class or struct).
  • It can also be a placeholder type specifier, such as auto or decltype(auto).

For example, when we talk about the "type-id of a new expression," we're specifically referring to the type specifier used in the allocation of memory for a new object using the new keyword.

  1. New Expression:

    • In C++, the new operator is used to dynamically allocate memory for an object or array.
    • Syntax: new Type-id or new Type-id [size] for array allocation.
  2. Type-id of a New Expression:

    • When we say "type-id of a new expression," we're referring to the Type-id used in the new expression.
    • This Type-id specifies the type of the object being allocated in memory.
    • For example:
      • new int allocates memory for an int.
      • new MyClass allocates memory for an object of type MyClass.
      • new auto or new decltype(expr) deduces the type from the initializer expression expr.