Originally Posted by
Elysia
I'm under the impression it is not.
Only across different compilation units. And even so you can control it through things like (according to the previous example):
hide.hpp
Code:
class foo {
public:
foo(): val_(12) {}
int getval() { return val_; }
private:
int val_;
};
test.cpp
Code:
#include "hide.hpp"
foo& getfoo() {
static foo bar;
return bar;
}
test.hpp
Code:
#include "hide.hpp"
foo& getfoo();
You then use test.hpp as your header file in main. This simple method guarantees you control over initialization order across different compilation units.
...
As for cout, this is simple because the C++ standard requires that cout, cin, cerr and its wide brothers and sisters be defined prior to any other user-defined objects. How it exactly goes about this, I'm unsure. Probably by having them already pre-compiled?
In any case, because of this you can even use cout and family on the destructors of your static objects on any compilation unit.