Why do we have reinterpret_cast in C++ when two chained static_cast can do its job?

后端 未结 7 1489
孤城傲影
孤城傲影 2020-12-01 01:58

Say I want to cast A* to char* and vice-versa, we have two choices (I mean, many of us think we\'ve two choices, because both seems to wor

7条回答
  •  长情又很酷
    2020-12-01 02:23

    You need reinterpret_cast to get a pointer with a hardcoded address (like here):

    int* pointer = reinterpret_cast( 0x1234 );
    

    you might want to have such code to get to some memory-mapped device input-output port.

提交回复
热议问题