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

  • Home
  • SEARCH
  • 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 1004183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:05:42+00:00 2026-05-16T08:05:42+00:00

In this contrived example, I have a static initialization function that is run at

  • 0

In this contrived example, I have a static initialization function that is run at construction time.

I’d like to know if this a legal way to initialize a_, b_, and c_. Or, is it too early in the construction process to use them this way?

DWORD SomeInitializationFunction( HANDLE*, DWORD*, DWORD* );

class MyClass
{
public:
    MyClass() : m_( MyClass::Create( &a_, &b_, &c_ ), &::CloseHandle )
    {
    };

private:

    static HANDLE Create( DWORD* a, DWORD* b, DWORD* c )
    {
        DWORD a1, b1;
        HANDLE h;

        *c = ::SomeInitializationFunction( &h, &a1, &b1 );
        if( *c == 0 )
        {
            *a = a1;
            *b = b1;
            return h;
        }
        return NULL;
    };

    boost::shared_ptr< void > m_;
    DWORD a_;
    DWORD b_;
    DWORD c_;
};

Thanks,
PaulH

  • 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-16T08:05:43+00:00Added an answer on May 16, 2026 at 8:05 am

    Members in a class are initialized in the order they are defined in the class. Thus if you have

    class A
        int t
        int u
        int v
    A() : v(0), u(1), t(2) {}
    

    Then despite the order in which you write the constructor arguments, first the value of t would be set, then the value of u and finally the value of v.

    So if you change the order of definition of your class to:

    class MyClass
    {
    public:
        MyClass() : m_( MyClass::Create( &a_, &b_, &c_ ), &::CloseHandle )
        {
        };
    
    private:
    
        static HANDLE Create( DWORD* a, DWORD* b, DWORD* c )
        {
            DWORD a1, b1;
            HANDLE h;
    
            *c = ::SomeInitializationFunction( &h, &a1, &b1 );
            if( *c == 0 )
            {
                *a = a1;
                *b = b1;
                return h;
            }
            return NULL;
        };
    
    
        DWORD a_;
        DWORD b_;
        DWORD c_;
        boost::shared_ptr< void > m_;
    };
    

    then your constructor should be okay.

    I’d suggest putting in a comment saying that there is a dependency in the initialization of the members of your class so that people reading the code would know not to fiddle around.

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

Sidebar

Ask A Question

Stats

  • Questions 541k
  • Answers 541k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Check out dogtail. May 17, 2026 at 2:51 am
  • Editorial Team
    Editorial Team added an answer An .egg file is a simple ZIP archive, you can… May 17, 2026 at 2:51 am
  • Editorial Team
    Editorial Team added an answer autoresizesForKeyboard is part of the Three20 library and is a… May 17, 2026 at 2:51 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

This may seem like a somewhat contrived example, but I'm left scratching my head.
$class = new Class; $foo = json_decode($_POST['array']); In this highly contrived example, I have
This is a contrived example, but consider a scenario where employees have working locations,
I have an interface - here's a nicely contrived version as an example: public
This example is a bit contrived; I've simplified it to remove extraneous details and
To use a contrived example in Java, here's the code: enum Commands{ Save(S); File(F);
In SQL Server assuming one has columns that need to have the same data
We have two websites that share some business processes and UI elements. Lets focus
Let's say I'm trying to match /dog.*lab/ against this text: I have a dog.
I require the syntax of a CMAKE macro that generates .cc and .h files

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.