The main reference is to understand the memory layout, and then write an instance program to understand it, but you need to be familiar with pointer conversion.
1) only polymorphism classes have RTTI information. dynamic_cast uses RTTI for conversion and is a runtime type check.
2) When determining whether two pointers can be converted using dynamic_cast, you can use RTTI to know the current actual object and traverse all of its parent classes to see if there is any type consistent with the target, if yes, it can be converted.
3) dynamic_cast is safe. You can check the return value or exception capture to determine whether the conversion is successful. The return value is used for pointer conversion, and the exception capture is used for reference conversion.
4) In addition, unlike static_cast, even if the two classes do not have a direct inheritance relationship, as long as they are in a class hierarchy, they may point to the same object, and dynamic_cast can be performed. For example, C inherits from A and B. A and B pointers can be used for dynamic_cast and may be successful.
C * pc = new C;
A * pa = pc;
B * pb = pc;
Pb = dynamic_cast <B *> (pa); // The conversion is successful because both point to the C object.
The following example is mainly about RTTI, which prints the runtime information of an object and all its parent classes. The runtime information here is mainly the class name.
#include <typeinfo> Base : Deri1234567890ve : mdisp; pdisp; vdisp; TypeDescriptor* pTypeDescriptor; DWORD numContainedBases; PMD ; DWORD attributes; DWORD attributes; DWORD numBaseClasses; RTTIBaseClassArray* TypeDescriptor* pTypeDescriptor; RTTIClassHierarchyDescriptor* pClassDescriptor; *pderive = *ptable = (*)*(* * rtti = ptable - RTTICompleteObjectLocator * RIIT_locator = (RTTICompleteObjectLocator *)( *(*<<RIIT_locator->pTypeDescriptor->name<< * p1 = (*)(RIIT_locator->pClassDescriptor-> * p2 = (*)*(p1+* pDesc = (TypeDescriptor*)(*<<<<pDesc->name<<= (*)(RIIT_locator->pClassDescriptor->= (*)*(p1 + = (TypeDescriptor*)(*<<<<pDesc->name<<= (*)(RIIT_locator->pClassDescriptor->= (*)*= (TypeDescriptor*)(*<<<<pDesc->name<<
Refer:
Discussion on Dynamic_cast and RTTI http://www.cnblogs.com/zhyg6516/archive/2011/03/07/1971898.html
Http://www.openrce.org/articles/full_view/23
Asdfasdf