Virtual inherited memory layout Codex-based VS2012

Source: Internet
Author: User

1, the total light on the paper, the bow of the debug is profound.

For the "Deep Exploration of C + + object Model" This type of book, the knowledge needed to be consolidated in time to achieve permanent memory.


2. There is a great relationship between the content layout and the reusability of virtual table after the realization of the merging branch of fictitious inheritance.

The order of inheritance determines the layout order of A and B, and then common the layout of the high address, the public virtual base class, at the tail of D.


Scenario 1:

Class A:public virtual common{...};

Class B:public virtual common{...; virtual void Notincommon () {}};

Class D:public A,public b{...}

The memory layout is:

D{a,b,common}; A and Common share a single virtual table


Scenario 1:

Class A:public virtual common{...};

Class B:public virtual common{...; virtual void Notincommon () {}};

Class D:public B,public a{...}

The memory layout is:

D{b,a,common}; High address from low address (view from top to bottom).


The inheritance list is somewhat equivalent to a variable declaration, which declares that the location holds a base class. D, a, common common a virtual table. Priority adjustment to be able to satisfy the status of single inheritance (to be continued.) ), and B is offset by. If the virtual table pointer of the current class is not visible in VS-this is unscientific, how could it not be found, in fact the virtual table pointer is the same as the last parent class object using the common one virtual table pointer variable. However, because the view is a base class object, it is said that there is no more virtual function for this derived object. Cond.


Virtual inherited memory layout Codex-based VS2012

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.