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

The Archive Base Latest Questions

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

Lately, I’ve been reading much about constructors from the well-received C++ FAQ . One

  • 0

Lately, I’ve been reading much about constructors from the well-received C++ FAQ. One of entries mentions that it’s always best to use initialization lists, as opposed to initializing class members within the code-block of the constructor itself.

This is because the compiler tends to create multiple copies of the class members, rather than simply one copy.

Example

Good

Foo::Foo( void )
    : mBar( new Bar ) //pointer to some memory address
{
}

Bad

Foo::Foo( void )
{
    mBar = new Bar;
}

One thing it also states (and, while this relates to constructors, it also relates to pure initialization of objects in general from even non-member functions ) is that when initializing an object through methods such as the following:

void f( void )
{
    Foo foo( Bar() ); //Bad.

    foo.x(); //error
}

You will, and I quote: "[declare] a non-member function that returns a Foo object".

(for more info, click the link above)

The Question

Because of this, is it unwise to have the following:

Geometry::Geometry( void )
    : mFaces( QVector< GLushort >() ),
      mFinalized( false ),
      mNormals( QVector< QVector3D >() ),
      mVerticies( QVector< QVector3D >() )

Or even this:

Geometry::Geometry( void )
    : mFaces( QVector< GLushort > ),
      mFinalized( false ),
      mNormals( QVector< QVector3D > ),
      mVerticies( QVector< QVector3D > )

Because of the way that these are allocated (i.e., the fact that these are non-pointers), it makes me wonder whether or not these objects even NEED initialization in the beginning. If they do, is this the correct method of going about it? Or, is there a better method of initialization?

How this relates to the question

This relates to the general question due to the way that the methodology behind C++ constructor initialization relates to both initializing objects using constructor functions, along with the fact that I am ignorant to whether or not objects allocated on the stack – or, so I believe anyway – (either way, objects without pointer allocation) even need initialization in the first place.

  • 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-28T05:21:39+00:00Added an answer on May 28, 2026 at 5:21 am

    If a member variable is of a class type with a user-declared default constructor, you do not need to explicitly mention it in the initialization list: its default constructor will be called anyway, during construction, before the body of the constructor is entered.

    If a member variable is a primitive type (like int or bool) or is of a class type that doesn’t have any user-declared constructors, you need to initialize it explicitly, otherwise it will not be initialized (and it will have an unknown value; you cannot read an uninitialized object).

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

Sidebar

Related Questions

Lately I have been reading about the Rack architecture in Passenger/Rails, and how it
Lately, I've been reading some code that has if (! (a == b) )
Lately I have been reading about web crawling, indexing and serving. I have found
Lately, I've gotten some weird linker errors. I've been taught that there's two ways
Lately I've been wondering if there's a difference between initializing the variables that have
Lately I have been thinking about investing in a worthy USB pen drive (something
Lately I have been finding that some of the ColdFusion applications on my production
Lately I realized that I had lost some files in one of my projects
Lately I've been getting very excited about the support for lambdas in VC2010. I'm
Lately I've been thinking a lot about functional programming. Perl offers quite a few

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.