我在我的代码中使用 dynamic_cast 来将指针转换为以下的某个类型:
Base *base = here storing the pointer;
Derived *derived = dynamic_cast<Derived*>(base);
如果基类没有类层次结构的指针,则强制转换失败并返回NULL。在下面几行代码中,我检查了NULL。所以没有问题。
我遇到了一个崩溃转储,我的应用程序由于dynamic_cast引发异常而崩溃。
我知道只有在使用引用类型时,dynamic_cast才会抛出异常。
请问当我像上面的源代码一样使用指针时,dynamic_cast何时会抛出异常?