title: How can I use a global variable in C++?
body: <p>I'm developping a Blackberry 10 mobile app. using the momentics IDE (BB Native SDK).</p>
  
  <p>In my application, I want to use global variables that will be shared by many classes. </p>
  
  <p>I tried the code below like described in this <a href="http://www.learncpp.com/cpp-tutorial/42-global-variables/" rel="nofollow">link</a>, but when I add the <strong><em>extern</em></strong> instruction before the declaration of the variable "<strong>g_nValue*</strong> " in the ".h" file, it returns the error <strong>"storage class specified for 'g_nValue'"</strong></p>
  
  <p>*/ global.cpp:</p>
  
  <pre><code>// declaration of g_nValue
  int g_nValue = 5;
  </code></pre>
  
  <p>*/ global.h:</p>
  
  <pre><code>#ifndef GLOBAL_H // header guards
  #define GLOBAL_H
  
  // extern tells the compiler this variable is declared elsewhere
  extern int g_nValue;
  
  #endif
  </code></pre>
  
  <p>Any one have an idea on this? I searched a lot and they all said that the <strong><em>extern</em></strong> instruction should not cause any trouble.</p>