title: Making Global Struct in C++ Program
body: <p>I am trying to make <strong>global</strong> structure, which will be seen from any part of the source code. I need it for my big Qt project, where some global variables needed. Here it is: 3 files (global.h, dialog.h &amp; main.cpp). For compilation I use Visual Studio (Visual C++). </p>
  
  <p><em>global.h</em></p>
  
  <pre><code>#ifndef GLOBAL_H_
  #define GLOBAL_H_
  
  typedef struct  TNumber {
      int g_nNumber;
  } TNum;
  
  TNum Num;
  
  #endif
  </code></pre>
  
  <p><em>dialog.h</em></p>
  
  <pre><code>#ifndef DIALOG_H_
  #define DIALOG_H_
  
  #include &lt;iostream&gt;
  #include "global.h"
  
  using namespace std;
  
  class   ClassB {
  public:
      ClassB() {};
  
      void    showNumber() {
          Num.g_nNumber = 82;
          cout &lt;&lt; "[ClassB][Change Number]: " &lt;&lt; Num.g_nNumber &lt;&lt; endl;
      }
  };
  
  #endif
  </code></pre>
  
  <p>and <em>main.cpp</em></p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include "global.h"
  #include "dialog.h"
  
  using namespace std;
  
  class   ClassA {
  public:
      ClassA() {
          cout &lt;&lt; "Hello from class A!\n";
      };
      void    showNumber() {
          cout &lt;&lt; "[ClassA]: " &lt;&lt; Num.g_nNumber &lt;&lt; endl;
      }
  };
  
  int main(int argc, char **argv) {
      ClassA  ca;
      ClassB  cb;
      ca.showNumber();
      cb.showNumber();
      ca.showNumber();
      cout &lt;&lt; "Exit.\n";
      return 0;
  }
  </code></pre>
  
  <p>When I`m trying to build this little application, compilation works fine, but the linker gives me back an error:</p>
  
  <p><code>1&gt;dialog.obj : error LNK2005: "struct TNumber Num" (?Num@@3UTNumber@@A) already defined in main.obj</code></p>
  
  <p>Is there exists any solution? </p>
  
  <p>Thanks.</p>