With rtti of C ++, you can display the type name of the polymorphism pointer during runtime.
Typeid (P). Name () is the current type of the polymorphism pointer
Typeid (* P). Name () is the most derived type of the polymorphism pointer.
This feature is particularly useful in the Observer mode:
Sometimes, after an observer registers with a subject and forgets to unregister its own instance before it is destroyed, it will trigger an operation on the invalid pointer in the subject notification.ProgramEven if it can be disconnected from the site, it can only be an invalid pointer. I don't know which class of instance it was then.
When such a problem occurs, the most derived type and its corresponding pointer address of each subscriber and deregister are printed on the subject subscription and logout interfaces. If the program crashes due to a callback, you can immediately view the type of the Invalid Pointer address based on the log that was printed.CodeOkay.
Of course, the premise is that you have enabled the rtti switch during program compilation.