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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:38:10+00:00 2026-05-28T06:38:10+00:00

Is the order of the initializers for a class’ constructor significant? So say I

  • 0

Is the order of the initializers for a class’ constructor significant?

So say I have:

class MyClass : BaseClass
{
      int a, b, c;

   public:
      MyClass(int);
}

e.g. 1:

MyClass::MyClass(int forBase) :
  a(7),
  b(14),
  c(28),
  BaseClass(forBase) { }

e.g. 2:

MyClass::MyClass(int forBase) :
  BaseClass(forBase),
  a(7),
  b(14),
  c(28) { }

Would example 1 do something different to example 2?

  • 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-28T06:38:10+00:00Added an answer on May 28, 2026 at 6:38 am

    Would example 1 do something different to example 2?

    No. Initialisation order is dictated by the standard, not by the order in which you write the initialisers:

    [C++11: 12.6.2/10]: In a non-delegating constructor, initialization
    proceeds in the following order:

    • First, and only for the constructor of the most derived class (1.8), virtual base classes are initialized in the order they appear on a depth-first left-to-right traversal of the directed acyclic graph of base classes, where “left-to-right” is the order of appearance of the base classes in the derived class base-specifier-list.
    • Then, direct base classes are initialized in declaration order as they appear in the base-specifier-list (regardless of the order of the mem-initializers).
    • Then, non-static data members are initialized in the order they were declared in the class definition (again regardless of the order of the mem-initializers).
    • Finally, the compound-statement of the constructor body is executed.

    In fact, if you write them in any other order and one depends on the other, you may well be warned about it:

    struct T {
       std::vector<int> v;
       int w;
    
       T(int w) : w(w), v(0, w) {}
    };
    
    int main() {
       T t(3);
    }
    
    // g++ 4.1.2:
    // t.cpp: In constructor 'T::T(int)':
    // Line 3: warning: 'T::w' will be initialized after
    // Line 2: warning:   '__gnu_debug_def::vector<int, std::allocator<int> > T::v'
    // Line 5: warning:   when initialized here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <fstream> using namespace std; ofstream out(order.out); #define CLASS(ID) class ID { \ public:
I have been creating a helper class for the Facebook PHP API in order
Suppose I have a class with 3 constructors, a default (no argument) constructor, a
I have a static class with a static constructor that takes some time (10-15
Order deny,allow deny from all allow from xx.xx.x.xx RewriteRule . - [F] I have
In order to debug I would like to dump certain variables on to my
In order to work with decimal data types, I have to do this with
In order to bring up the menu for a DataGridViewComboBoxCell, I first have to
Here is the problem I'm running into - I have a GUI class implementing
If I have Order entity with a list of OrderDetails I can easily eager

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.