multiple inheritance: unexpected result after cast from void * to 2nd base class

后端 未结 3 854
忘掉有多难
忘掉有多难 2020-12-01 19:18

My program needs to make use of void* in order to transport data or objects in dynamic invocation situation, so that it can reference data of arbitrary types, even primitive

3条回答
  •  悲&欢浪女
    2020-12-01 20:13

    A static_cast or a dynamic_cast in presence of multiple inheritance may change the representation of the pointer by offsetting it so that it designate the correct address. static_cast determines the correct offset by considering static typing information. dynamic_cast does it by checking the dynamic type. If you go throw void*, you are loosing all static typing information and the possibility to get dynamic typing information, so the reinterpret_cast you are using is assuming that the offset is null, failing some times.

提交回复
热议问题