title: Global instances of class (across multiple files)
body: <p>I am working on a project in C::B and need to use global instances of classes, across the multiple project files. (I'm new to usage of header files and global classes)<br>
  I have declared, defined, initialized classes and functions thus:</p>
  
  <p>//in complex.h</p>
  
  <pre><code>class Julia
  {
      public:
      double R;
      double I;
      void algorithm();
  };
  Julia J;
  </code></pre>
  
  <p>//in complex.cpp</p>
  
  <pre><code>#include "complex.h"
  void Julia::algorithm()
  { 
      //fn body here
  }
  </code></pre>
  
  <p>//in main.cpp</p>
  
  <pre><code>#include"complex.h"
  int main()
  {
      //calls initialize() and display()
  }
  
  void initialize()
  {
      //...some code(irrelevant)
      cin&gt;&gt;J.R&gt;&gt;J.I;
  }
  
  void display()
  {
      J.algorithm();
      //some more (irrelevant) code
  }
  </code></pre>
  
  <p>On building and running the code, I get the error- "first defined here" and the Build log shows :</p>
  
  <p>obj\Debug\complex.o:complex.cpp:(.bss+0x3bf0): multiple definition of `J'
  obj\Debug\main.o:C:/Users/ShA/Documents/etf_build/main.cpp:20: first defined here</p>
  
  <p>[This is for my 12th grade school project, and I don't think I would be allowed to use singletons (restrictions), even though they seem to be suitable. ]</p>
  
  <p>Can somebody point out the possible errors in the code and how to find a solution to the errors I'm getting?  </p>