Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7650279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:12:39+00:00 2026-05-31T11:12:39+00:00

I am a freshman in C++, especially about object-oriented programming. And now I have

  • 0

I am a freshman in C++, especially about object-oriented programming. And now I have a problem during my learning.

There is a class hierarchy following:

class Class{};

class Base:public Class{};

class Derived1:virtual public Base{};

class Derived2:virtual public Base{};

class MI:public Derived1,public Derived2{};

class Final:public MI,public Class{};

And now I want to know what the order of constructor for the definition of a Final class object is.

I draw a diagram:
enter image description here
structure of class inheritance http://hi.csdn.net/attachment/201203/16/2712336_1331902452BziD.jpg

I know Virtual base classes are always constructed prior to nonvirtual base classes regardless of where they appear in the inheritance hierarchy. What I am confused is that if constructor of class Class is before Base, and if constructor of Class is invoked twice. And why?

Can someone tell my the answer? The more detailed, the better.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:12:40+00:00Added an answer on May 31, 2026 at 11:12 am

    The direct inheritance of Class by Final and Base is not virtual, so an instance of Final has two base class subobjects of type Class. The one that is the direct base of Base is constructed before Base, and the one that is the direct base of Final is constructed afterwards (in fact after MI).

    The reason is that:

    1. direct bases are constructed in the order they’re listed (unless they’re a virtual base that has been constructed already),
    2. bases are constructed before the class’s own constructor runs.

    Applying (1) to Final tells us that Class is constructed after MI. Applying (2) several times tells us that Class is constructed before Base, before Derived1 and Derived2, before MI.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey - great coders and haskellers, i'm a haskell freshman and have a problem
The following is a scheme for a databse in an object-oriented setting. Every relation
I’m a freshman on Ruby and now trying to install ruby on my machine
I am working now with the Apache Directory Server. I am a freshman in
My brother-in-law is a freshman engineering major in college. He has no prior programming
So if I have an instance of System.Reflection.Assembly and I have the following model:
I'm a freshman in college, who's taking a python coding class. Currently I'm working
I'm a college CS freshman who wishes to learn a version control system well.
I am the freshman for flex and actionscript. I want to know when a
I was thinking back to my freshman year at college (five years ago) when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.