Why doesn't this reinterpret_cast compile?

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

    reinterpret_cast is not a general cast. According to the C++03 spec section 5.2.10.1:

    Conversions that can be performed explicitly using reinterpret_cast are listed below. No other conversion can be performed explicitly using reinterpret_cast.

    And there is nothing listed that describes converting between integral and floating point types (or between integral types, even this is illegal reinterpret_cast(int(3));)

提交回复
热议问题