title: What is the best way to declare a global variable?
body: <p>In C++, say you want to declare a global  variable to be used by many. How do you do it?</p>
  
  <p>I commonly use declare and define in cpp file, and then use extern  in other cpp file (and not headers).</p>
  
  <p>I don't like this approach, and I am considering something along these lines:</p>
  
  <p>In a header file:</p>
  
  <p>some_file.h</p>
  
  <pre><code>Class MYGlobalClass
  {
  
  };
  
  
  MyGlobalClass&amp; MyGlobalClassInstance()
  {
     static MYGlobalClass instance; 
     return  instance;
  
  }
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p><strong><em>Consider  in the following contexts:</em></strong> </p>
  
  <ul>
  <li>can be used in multi-threaded applications</li>
  <li>namespace pollution</li>
  <li>may NOT necessery be a singleton, as many instances of this might be created </li>
  </ul>
  
  <p>What are your thoughts, suggestions, new ideas?</p>