title: Is initialization of static member of a class guaranteed before initialization of a static object of that class?
body: <p>I encountered this C++ static initialization order related query at a code review recently. </p>
  
  <ol>
  <li>I've a class with static member variable in a compilation unit</li>
  <li>I've a static object of that class using a constructor in a different compilation unit</li>
  </ol>
  
  <p>Here, I want to know if the static member variable is guaranteed to be initialized before the static object constructor is called?</p>
  
  <p><em>MyClass.h</em>:</p>
  
  <pre><code>typedef int (*MyFunc)(int);
  class MyClass {
  MyClass(MyFunc fptr) {
      mFunc = fptr;
  }
  static MyFunc mFunc;
  }
  </code></pre>
  
  <p><em>MyClass.cpp</em>:</p>
  
  <pre><code>MyFunc MyClass::mFunc = nullptr;
  </code></pre>
  
  <p><em>MyDifferentClass.h</em>:</p>
  
  <pre><code>MyDifferentClass {
  public:
      static int MyStaticFunc(int);
  }
  </code></pre>
  
  <p><em>MyDifferentClass.cpp</em>:</p>
  
  <pre><code>static MyClass myClassObj(MyDifferentClass::MyStaticFunc);
  </code></pre>
  
  <p>In the code, would <code>mFunc</code> be initialized to <code>nullptr</code> before <code>myClassObj</code> gets created? The reason for the query is that if the order is not guaranteed, then <code>mFunc</code> may get initialized again to <code>nullptr</code>.</p>