sdm@cs.brown.edu (Scott Meyers) (07/20/90)
What's the latest story on initialization order of statics and globals? In
particular, can one rely on static data members of a class being
initialized before global objects of that class? For example:
class OneOnly {
private:
static int objectCount;
public:
OneOnly()
{
if (objectCount++ > 1) error("Too many objects");
}
};
int OneOnly::objectCount = 0;
OneOnly thisObject;
Can I rely on OneOnly::objectCount being initialized before thisObject? I
took a look at E&S, but I'm still unclear on this point.
(By the way, I know that statics are pre-initialized to 0, so the question
for this example is moot, but the general question remains...)
Thanks,
Scott