C++: can't static_cast from double* to int*

前端 未结 5 2108
梦如初夏
梦如初夏 2020-12-17 10:01

When I try to use a static_cast to cast a double* to an int*, I get the following error:

invalid static_cast from type ‘double*’ to type ‘int*’
5条回答
  •  鱼传尺愫
    2020-12-17 10:30

    You can convert between a double and an int with static_cast<>, but not between pointers to different types. You can convert any pointer type to or from void * with static_cast<>.

    The rationale may be that int * and double * are often effectively arrays, and the implementation doesn't know how big the array is.

提交回复
热议问题