Type name of the polymorphism pointer displayed during runtime

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.