What is the dynamic type of the object allocated by malloc?

后端 未结 5 1993
挽巷
挽巷 2021-01-12 09:31

The C++ standard refers to the term "dynamic type" (and the C standard refers to "effective type" in the similar context), for example

<
5条回答
  •  借酒劲吻你
    2021-01-12 09:55

    According to the C++ specification:

    Dynamic type:

    type of the most derived object (1.8) to which the glvalue denoted by a glvalue expression refers

    The return value of malloc is a block of uninitialized storage. No object has been constructed within that storage. And therefore it has no dynamic type.

    The void* does not point to an object, and only objects have a dynamic type.

    You can create an object within that storage by beginning its lifetime. But until you do so, it's just storage.

提交回复
热议问题