static definitions

L

LuB

Hi,

I know that instance members are instantiated in the order they are
declared.

Does the same hold true for static class members?



Is the following well-defined?


-----------------------------------------------


struct A
{
int a;
};

class B
{
static A a_;
static int b_;
}

....

A B::a_ = { 1 };

// IS *THIS* WELL DEFINED?
int B::b_ = B::a_.a;


-----------------------------------------------



Please pardon any typos ... thanks,

-Luther
 
V

Victor Bazarov

LuB said:
I know that instance members are instantiated in the order they are
declared.

Does the same hold true for static class members?

No. They are initialised in the order they are _defined_.
Is the following well-defined?


-----------------------------------------------


struct A
{
int a;
};

class B
{
static A a_;
static int b_;
}
^^^
No, not well-defined. Forgot a semicolon here.
...

A B::a_ = { 1 };

// IS *THIS* WELL DEFINED?
int B::b_ = B::a_.a;
Yes.

Please pardon any typos ... thanks,

Well... OK, the absence of the semicolon _can_ be viewed as
a typo, of course. I'll leave my note in, however.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top