Why doesn't this reinterpret_cast compile?

前端 未结 11 708
暗喜
暗喜 2020-12-04 16:32

I understand that reinterpret_cast is dangerous, I\'m just doing this to test it. I have the following code:

int x = 0;
double y = reinterpret_c         


        
11条回答
  •  我在风中等你
    2020-12-04 16:43

    reinterpret_cast is best used for pointers. So a pointer to one object can be turned into a "submarine".

    From msdn:

    The reinterpret_cast operator can be used for conversions such as char* to int*, or One_class* to Unrelated_class*, which are inherently unsafe.

    The result of a reinterpret_cast cannot safely be used for anything other than being cast back to its original type. Other uses are, at best, nonportable.

提交回复
热议问题