Values for C + + virtual function table pointers

Source: Internet
Author: User

The previous time in the software writing process encountered a problem, by the way to write, although do not know whether with the implementation of the compiler, but the constraints of their own code to write the habit is always right.

Changes of pointer values for base-class virtual function tables

The Destructors class contains virtual functions, and when a derived class object is created, the value of the virtual function table pointer is modified to point to the newly created virtual function table of the derived class when it enters the function body of the derived class constructor. When a base class destructor is called, the value of the virtual function table pointer is modified to point to the virtual function table created by the base class to prevent access to the portion of the memory (especially important) of the derived class that may be freed in the base class destructor. Once a derived object invokes a base class destructor, all base class pointers to that derived object lose polymorphism. Therefore, it is recommended to separate the functionality from the virtual function for some purpose (not destroying the object).

Values for C + + virtual function table pointers

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.