B
BigMan
Does the standard define the order in which static members of a class
are created and initialized?
are created and initialized?
BigMan said:Does the standard define the order in which static members of a class
are created and initialized?
BigMan said:Could you tell where in the standard this is stated?
Static members of the class are initialised in the order in which they
are defined. Just like any other namespace object with static storage
duration.
If they are defined in different translation units, the relative
initialisation order is unspecified.
Axter said:Actually, it's not that simple.
POD objects will get initialize before non-POD non-constant object.
Even that is not entirely accurate.
The order of initialization depends on some of the following factors
Is object initialize to zero
Is object constant
Is object POD
Order of definition
[..]
Do you have any proof of this? How is initialising with 0 versus with
something else affects the order? Imagine your translation unit has
this single declaration statement:
int a = 0, b = 42, c = 0;
what is the order of things initialised?
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.