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

前端 未结 5 2125
梦如初夏
梦如初夏 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:43

    Aside from being pointers, double* and int* have nothing in common. You could say the same thing for Foo* and Bar* pointer types to any dissimilar structures.

    static_cast means that a pointer of the source type can be used as a pointer of the destination type, which requires a subtype relationship.

提交回复
热议问题