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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:44:34+00:00 2026-05-10T18:44:34+00:00

I noticed some code of a colleague today that initialized class variables in the

  • 0

I noticed some code of a colleague today that initialized class variables in the initialization. However it was causing a warning, he says because of the order they are in. My question is why is it better to do variable initialization where it currently is and not within the curly brackets?

DiagramScene::DiagramScene( int slideNo, QRectF screenRect, MainWindow* parent )     : QGraphicsScene( screenRect, parent ),     myParent( parent ),      slideUndoImageCurrentIndex(-1),     nextGroupID(0),     m_undoInProgress(false),     m_deleteItemOnNextUndo(0)     line(0),     path(0) {     /* Setup default brush for background */     scDetail->bgBrush.setStyle(Qt::SolidPattern);     scDetail->bgBrush.setColor(Qt::white);     setBackgroundBrush(scDetail->bgBrush);  } 
  • 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. 2026-05-10T18:44:34+00:00Added an answer on May 10, 2026 at 6:44 pm
    • It is more efficient (in general). All members of a class are initialised in the constructor, whether you explicitly initialise them or not. If you do not specify an initialiser, then the default constructor of the member is run. If you assign a value in the constructor body, then the assignment operator is called again. This does not apply to scalar values, as in your example, since scalar values do not have constructors.
    • You can’t accidentally assign a value twice in the initialiser list.
    • The compiler can check to make sure that the order in which you write the initialisers matches the order in which the members are defined in the class. The C++ standard requires that the members are initialised in the order they are declared, regardless of the order you write the initialisers. Having the compiler check this order ensures that the programmer knows which order the initialisers will be run in (again, this is more important for non-POD members than for scalars).
    • Reference types and const members must be initialised in the initialiser list, because you can’t assign to a reference or to a const member.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was playing around with some Javascript snippets today and noticed that this code
In some code I'm working on I have noticed that several variables are being
I was porting some code from select() to kqueue() today, and I noticed that
I looked through some code and noticed that the convention was to turn pointer
I saw this in some code: $(<p/>).append(<div>something</div>).appendTo(body); and noticed that it automatically closed the
I was going through some code and noticed that UPDATE LOW_PRIORITY and INSERT DELAYED
Noticed a strange thing today. I have some code like this in a project
I've noticed some code that uses the static method: Regex.IsMatch([someRegexStr], [someInputStr]) Is it worth
I noticed in some code in this sample that contained the >> operator: let
I'm working on some code I didn't write and noticed that there are many

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.