title: Using void in header file
body: <p>This is my header file, auto vs static.h</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  
  void IncrementAndPrint()
  {
      using namespace std;
      int nValue = 1; // automatic duration by default
      ++nValue;
      cout &lt;&lt; nValue &lt;&lt; endl;
  } // nValue is destroyed here
  
  void print_auto()
  {
      IncrementAndPrint();
      IncrementAndPrint();
      IncrementAndPrint();
  }
  
  void IncrementAndPrint()
  {
      using namespace std;
      static int s_nValue = 1; // fixed duration
      ++s_nValue;
      cout &lt;&lt; s_nValue &lt;&lt; endl;
  } // s_nValue is not destroyed here, but becomes inaccessible
  
  void print_static()
  {
      IncrementAndPrint();
      IncrementAndPrint();
      IncrementAndPrint();
  }
  </code></pre>
  
  <p>And this is my main file, namearray.cpp</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include "auto vs static.h"
  using namespace std;
  
      int main(); // changing this to "int main()" (get rid of ;) solves error 5. 
      {
      print_static();
      print_auto();
      cin.get();
      return 0;
      }
  </code></pre>
  
  <p>I'm trying to print (cout)
  2
  2
  2
  2
  3
  4</p>
  
  <p>Errors:</p>
  
  <p><img src="https://i.stack.imgur.com/x8F6J.png" alt="Errors"></p>
  
  <p>I feel that my mistake is just using void in the header file. How can I change the header file so that my code will work?</p>
  
  <p>Reference: code from <a href="http://www.learncpp.com/cpp-tutorial/41-blocks-compound-statements-and-local-variables/" rel="nofollow noreferrer">learncpp</a></p>