c++staticword-wrapstatic-initializationstatic-order-fiasco

Prevent static initialization order "fiasco", C++


Once I was reading an awesome C++ FAQ (It is really good!!) and read the topic about how to prevent the static initialization order "fiasco". So the author advises to wrap the static variables into functions, thus to prevent the "fiasco" by maintaining the creation order of variables. But this seems to me a rude workaround. So my question is, is there any modern, more pattern oriented way to prevent this "fiasco" but to wrap the "static stuff" into functions???


Solution

  • The modern, more pattern-oriented way is not to use globals in the first place.

    There's no other way around it.

    It wouldn't be much of a "fiasco", otherwise!