Conversion in C ++ type --STATIC

xiaoxiao2021-03-06  40

Static_cast Versus ReinterPret_cast

Static_cast and reinterpret_cast operat modify the operand type. They are not reversible; Static_cast is executed using the type information when compiling, and the necessary detection (such as pointer is calculated, type check). The number of operands are relatively safe On the other hand, ReinterPret_cast is only reinterpretation of the bits of the object given without carrying binary conversion, as follows:

INT n = 9; double d = static_cast (n);

In the above example, we convert a variable from int to Double. These types of binary expressions are different. To convert integer 9 to double precision integer 9, Static_cast needs to be correctly double precision integer D to make up bit. The result is 9.0. The behavior of ReinterPret_cast is different:

INT n = 9;

Double D = Reinterpret_cast (n);

This time, the results are different. After the calculation, D contains unused values. This is because ReinterPret_cast is just a bit bit to D, no necessary analysis.

Therefore, you need to use ReinterPret_cast.

-----------

Danny Kalev

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

New Post(0)