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 7912863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:42:34+00:00 2026-06-03T13:42:34+00:00

I’m running into a strange error when a constructor is called for one of

  • 0

I’m running into a strange error when a constructor is called for one of my classes. Essentially, what I’m doing is this:

I have a class “A”, that has two member variables of type “B”, “C”. “C” has to be initiated with a member of type “B”. So the constructor has to be:

A::A():
c(b)
{}

This works fine if the class is laid out as:

class A
{
   B b;
   C c;
}

But crashes if the class is laid out as:

class A
{
   C c;
   B b;
}

My first guess was that, of course b has to be created before c if I’m going to
initialize c(b) in the constructor. I don’t know if this is correct though. Is
the constructor called before any member variables are allocated? Or are the
member variables referenced in the constructor allocated first and then any remaining
unreferenced member variables allocated at the end of the constructor (like for example if there was
another member variable “C c2” that is unreferenced in the constructor)?

I am on Visual Studio 2010.

  • 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-06-03T13:42:36+00:00Added an answer on June 3, 2026 at 1:42 pm

    So, the way this works is that:

    1. Construction of your object begins.
    2. non-virtual base classes are constructed in order of declaration.
    3. virtual base classes are constructed in order of declaration.
    4. The current class part is created (initializing any vtable and such).
    5. Member variables are constructed in order of appearance in the class declaration, not the initializer list.
    6. Your constructor body is executed.
    7. Construction of your object is complete.

    I could be mistaken about the placement of #3, I rarely use virtual bases and rarely write code that depends on this stuff. Why? Because it’s complicated and such code is extremely fragile.

    Destruction happens in exactly the opposite order.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am currently running into a problem where an element is coming back from
I have some data like this: 1 2 3 4 5 9 2 6

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.