Suppose I have a class A and a class B that is derived from A. Now, I want to cast a const A* (called "a") to a B* using dynamic_cast (see below). If "a" really was a B*, then my resulting object pointer should be fine. If "a" was not a B*, then I will get NULL.
const A* a = new B();
const B* b = dynamic_cast<const B*>(a);
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
#0 0x0000000000000000 in ?? ()
#1 0x00007ffff6c0e612 in __cxxabiv1::__dynamic_cast (src_ptr=<optimized out>,
src_type=0x4fa6b0, dst_type=0x516bb0, src2dst=0)
Reasons which can cause a crash when using dynamic_cast
Verify if one of these cases is applicable to you.