title: C++ Global variable declaration
body: <p><br>
  What I want to do is just to define a variable in a header file and use it on two different cpp files without redefinition that variable each time I include that header<br>
  Here is how I tried :<p>
  Variables.h</p>
  
  <pre><code>#ifndef VARIABLES_H // header guards
  #define VARIABLES_H
  
  static bool bShouldRegister;
  
  #endif
  </code></pre>
  
  <p>(I also tried extern but nothing changed)</p>
  
  <p>And in a cpp file I give it a value <code>::bShouldRegister = true</code> or <code>bShouldRegister = true;</code></p>
  
  <p>In my another cpp file I check it's value by creating a thread and check its value in a loop (and yes my thread function works well)</p>
  
  <pre><code> while (true)
   {
       if (::bShouldRegister) // Or if (bShouldRegister)
          {
              MessageBox(NULL,"Value Changed","Done",MB_OK|MB_ICONINFORMATION);
          }
    Sleep(100);
   }
  </code></pre>
  
  <p>And yes, that MessageBox never appears (bShouldRegister never gets true :/)</p>