Several conversions in C ++

xiaoxiao2021-03-06  41

The meaning of the conversion in the C language is that the compiler You see XXX as this type will bring unsafe, so C is changed to convert, and provide four keywords:

STATIC_CAST basically function is consistent with C conversion (the compiler you regard XXX as this type), but the function has weakened, for example: cannot convert the pointer into an int type.

1. THE Static_cast Operator CAN BE Used for Operations Such AS Converting a Pointer To A Base Class. (Class Pointer Conversion) Note: When there is a class of inheritance, Static_CAST determines the child according to the mode of movement. The parent class included in the class (Application Principle in COM is here), because the compiler has sufficient information to know where the pixel of the parent class in the subclass is.

2. In General You Use static_cast when Want To Convert Numeric Data Types Suqing, and You Are Certain of The Data Types Involved in The Conversion. (Basic Data Types)

Const_cast converts const_cast to non-Const, but can only be converted to a corresponding type of non-Const type to convert Volatile into non-Volatile, you don't have to convert into a corresponding type of Volatile

Dynamic_cast

With the RTII function to check the pointer type at runtime, that is, it is safe when the class pointer is converted down, it can identify the type. The conversion is successfully returned to the corresponding pointer, otherwise it returns 0

Reinterpret_cast

It is the meaning of reinterpretation.

The Reinterpret_cast Operator Allows Any Pointer TOBE Converted Into Any Other Pointer Type. It also allows any integral type to be converted Into Any Pointer Type And Vice Versa.

From the pointer to the shaping OK from the shaping to the pointer OK

From pointer to pointer OK

转载请注明原文地址:https://www.9cbs.com/read-72679.html

New Post(0)