order of initialization of static class objects

B

benben

Hi all! Does the standard say anything about the order of initialization of
static class objects? For example:

class A{};

class B
{
static A a;
};

class C
{
static A a;
};

//...

Is it specified that B::a will always be initialized earlier than C::a?

Ben
 
?

=?iso-8859-1?q?Stephan_Br=F6nnimann?=

No, it depends on the implementation:

If in classes.cc, you have:
// ...
A C::a;
A B::a;
// ...
C::a will be initialized before B::a.

If the two class statics are defined in two different
implementation files, then the order of initialisation
is unspecified by the standard.

Stephan
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top