What could cause a dynamic_cast to crash?

前端 未结 6 1082
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-06 16:58

I have a piece of code looking like this :

TAxis *axis = 0;
if (dynamic_cast(obj))
   axis = (dynamic_cast         


        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-06 17:15

    Some possible reasons for the crash:

    • obj points to an object with a non-polymorphic type (a class or struct with no virtual methods, or a fundamental type).
    • obj points to an object that has been freed.
    • obj points to unmapped memory, or memory that has been mapped in such a way as to generate an exception when accessed (such as a guard page or inaccessible page).
    • obj points to an object with a polymorphic type, but that type was defined in an external library that was compiled with RTTI disabled.

    Not all of these problems necessarily cause a crash in all situations.

提交回复
热议问题