Why can't I reinterpret_cast uint to int?

后端 未结 7 1103
借酒劲吻你
借酒劲吻你 2020-12-29 23:40

Here\'s what I want to do:

const int64_t randomIntNumber = reinterpret_cast (randomUintNumber);

Where randomUintNumber is of type

相关标签:
7条回答
  • 2020-12-30 00:22

    No, it is not. reinterpret_cast is mostly intended to reinterpret an existing bit of storage as a different type than it is. A lot of these interpretations is implementation dependent, and the standard lists a specific (rather long to quote here) list of things that can be done with a reinterpret_cast (mostly casting between different pointer/reference types), but says:

    No other conversion can be performed explicitly using reinterpret_cast.

    In your case, you probably want a conversion of types, not a reinterpretation of existing storage. Use static_cast for this purpose.

    0 讨论(0)
提交回复
热议问题