Why doesn't this reinterpret_cast compile?

前端 未结 11 688
暗喜
暗喜 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:51

    If you are trying to convert the bits of your int to a the representation of a double, you need to cast the address not the value. You must also make sure the sizes match:

    uint64_t x = 0x4045000000000000;
    double y = *reinterpret_cast(&x);
    

提交回复
热议问题