Initialization Order of Static Const Member Arrays

I have a class that contains several private static const member arrays. One of the arrays needs to be initialized using values from the other two. What is the rule on initialization order for these types of arrays? Is it the order they are declared in the class? I am concerned that arr3 may be initialized before arr1 or arr2.
.h file

class A
{
private:
static const float arr1[2];
static const float arr2[3];
static const float arr3[4];
};

.cpp file

const float A::arr1[2] = {1.0, 2.0};

const float A::arr2[3] = {1.0, 2.0, 3.0};

const float A::arr3[4] = {arr1[0] + arr2[0],
arr1[1] + arr2[0],
arr1[0] + arr2[1],
arr1[1] + arr2[1],
arr1[0] + arr2[2],
arr1[1] + arr2[2]};

Last edited on
closed account (DSLq5Di1)
This will be fine, you need only worry about order when initializing objects across translation units, ie..

1
2
3
4
5
// A.cpp
static int A::foo = 666

// B.cpp
static int B::bar = A::foo

http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.14
Thank you.

So the rule is that the static arrays are initialized in order they appear in the .cpp? Does the fact that they're static members of a class have any impact?
closed account (DSLq5Di1)
Yep, the order of initialization is the order in which they are defined in, and whether they are static members of a class or not has no consequence.

Just be wary of the the example I gave above, there is no guarantee in what order your cpp files will be compiled.
Topic archived. No new replies allowed.