C + + Multiple inheritance constructor call order

Source: Internet
Author: User

//With a typical example description
1 classb1{};2 classV1: PublicB1 ();3 classD1:Virtual PublicV1 ();4 classb2{};5 classb3{};6 classV2: Publicb1,publicb2{};7 classD2:Virtual PublicV2, Publicb3{};8 classm1{};9 classm2{};Ten classX: PublicD1, PublicD2 One { A M1 m1_; - M2 m2_; -};

Constructor Call Order:

1. First, construct the virtual base class sub-object;

Construction V1:B1::B1 () v1::v1 ()

Construction V2: b1::b1 () b2::b2 () v2::v2 ()

2. Secondly, constructs the non-virtual base class sub-object;

Construction D1:D1::D 1 ()

Construction d2:b3::b3 () D2::D 2 ()

3. once again, construct all members : m1::m1 () m2::m2 ( )

4. Finally, construct X itself X::x ()

C + + Multiple inheritance constructor call order

Related Article

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.