title: Initializing variables in header C++
body: <p><strong>EDIT:</strong> correct function names, and added #pragma once</p>
  
  <p>This is a very strong simplification of my problem, but if I do this:</p>
  
  <p>A.h</p>
  
  <pre><code>#pragma once
  static int testNumber = 10;
  void changeTestNumber();
  </code></pre>
  
  <p>A.cpp</p>
  
  <pre><code>#pragma once
  #include "A.h"
  
  void changeTestNumber()
  {
      testNumber = 15;
  } 
  </code></pre>
  
  <p>B.h</p>
  
  <pre><code>#pragma once
  #include "A.h"
  // some other stuff
  </code></pre>
  
  <p>B.cpp</p>
  
  <pre><code>#pragma once
  #include "B.h"
  // some other stuff
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#pragma once
  #include "B.h"
  #include &lt;iostream&gt;
  
  int main(){
  
  changeTestNumber();
  std::cout&lt;&lt;testNumber&lt;&lt;std::endl;
  
  return 0;
  }
  </code></pre>
  
  <p>Why am I not getting testNumber = 15 at the call out?
  What really happens when I use a function that is included in a header of my included header?
  If I remove the <em>static</em> in from of <em>int testNumber</em>, I will get some error about my testNumber being initialized twice. </p>
  
  <p>So is my header compiled twice when I do this?</p>
  
  <p>Thanks in advance!</p>