Non-local objects with static lifetime duration in the same translation unit (source file) are initialized in the order of their definition in that translation unit, not in alhphabetical order. The de-initialization occurs in reverse order. The initialization order across translation units is unspecified - i.e. does not depend on the lexicographic ordering of the source file names, or something like that.
If I understand correctly, you rely on the fact that non-locals in files with 'alphabetically lower' names will be initialized
before non-locals in source files with lexicoraphically larger names..?! Don't do it, this will result in the typical static order initialization fiasco. One way to go would be the following:
class DeserializableClassMapEntry {
private:
static DeserializedObjectFunctionMap& GetObjectMap() {
static DeserializedObjectFunctionMap sMap;
return sMap;
}
public:
DeserializableClassMapEntry(
const char * classNameString,
pReturnDeserializedObjectFunction returnDeserializedObjectFunction) {
GetObjectMap()[ classNameString ] = returnDeserializedObjectFunction;
}
};
You could yous a similar pattern for taking care of proper initialization of the
mapEntry
static class objects.