Consider the following code:
class Foo {
public:
static const char one[];
static const char two[];
static const char* all[];
};
const char Foo::one[] = "one";
const char Foo::two[] = "two";
const char* Foo::all[] = {Foo::one, Foo::two};
int main()
{
for (const auto& x: Foo::all) {
std::cout << x << std::endl;
}
return 0;
}
If works as expected, but I am using static variables (one
and two
) to initialize another static variable. Can I run into static initialization order fiasco here?
I can also add constexpr
to all declarations and move initialization to declaration:
class Foo {
public:
static const constexpr char one[] = "one";
static const constexpr char two[] = "two";
static const constexpr char* all[] = {one, two};
};
Will it change anything with respect to static initialization order fiasco?