title: Already defined error with operator overloading
body: <p>When debugging my program I keep getting these two errors: </p>
  
  <blockquote>
    <p>main.obj : error LNK2005: "class std::basic_istream > &amp; __cdecl operator>>(class std::basic_istream > &amp;,class Complex &amp;)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVComplex@@@Z) already defined in Imaginary.obj</p>
    
    <p>1>main.obj : error LNK2005: "class std::basic_ostream > &amp; __cdecl operator&lt;&lt;(class std::basic_ostream > &amp;,class Complex const &amp;)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABVComplex@@@Z) already defined in Imaginary.obj</p>
  </blockquote>
  
  <p>I have tried restarting my project to make sure that I created a console application and not something else on accident but that didn't work. Any direction would be greatly appreciated. </p>
  
  <p>Here's my code:</p>
  
  <p>imaginary.h</p>
  
  <pre><code>#ifndef imaginary_h_
  #define imaginary_h_
  
  #include &lt;iostream&gt;
  
  class Complex
  {    
      friend std::ostream &amp; operator &lt;&lt; (std::ostream&amp; os, const Complex&amp;);
      friend std::istream &amp; operator &gt;&gt; (std::istream&amp; is, Complex&amp;);
  
  private:    
      double real;
      double imag;
      char op;
  
  public:    
      double r = real;
      double i = imag;
      char o = op;
  
      Complex()
      {    
      }
  
      Complex(double r, double i, char o)
      {    
      }
  
      bool userTest();    
  };
  
  #endif
  
  std::ostream &amp; operator &lt;&lt; (std::ostream &amp; os, const Complex &amp; complex)    
  {
      os &lt;&lt; complex.r &lt;&lt; complex.o &lt;&lt; complex.i &lt;&lt; "i" &lt;&lt; "/n" &lt;&lt; "/n";
      return os;
  }
  
  std::istream &amp; operator &gt;&gt; (std::istream &amp; is, Complex &amp; complex)    
  {
      is &gt;&gt; complex.r &gt;&gt; complex.o &gt;&gt; complex.i;
      return is;
  }
  </code></pre>
  
  <p>Imaginary.cpp</p>
  
  <pre><code>#include "imaginary.h"    
  #include &lt;iostream&gt;
  
  bool Complex::userTest()
  
  {
      if (op == '+' || op == '-')
  
      {
          return true;
      }
  
      else
  
      {
          std::cout &lt;&lt; "Incorrect operand entry, please enter complex number as x+yi" &lt;&lt; "/n" &lt;&lt; "/n";
  
                  return false;
      }
  
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include "imaginary.h"
  
  #include &lt;iostream&gt;
  
  
  int main()
  {
      double userInput;
  
      std::cout &lt;&lt; "Here you will add or subtract complex numbers." &lt;&lt; "/n" &lt;&lt; "/n";
  
      do
  
      {
  
          std::cout &lt;&lt; "Please enter the real part of you complex number: " &lt;&lt; "/n" &lt;&lt; "/n";
  
                  Complex complex;
  
          std::cin &gt;&gt; complex;
  
          std::cout &lt;&lt; "/n" &lt;&lt; "/n" &lt;&lt; "/n/t" &lt;&lt; "Note: Remember to enter your complex number in the format of x+yi to avoid an error";
  
                  if (complex.userTest())
                  {
                      std::cout &lt;&lt; complex &lt;&lt; "/n" &lt;&lt; "/n";
                  }
  
          std::cout &lt;&lt; "Would you like to perform another complex number operation? " &lt;&lt; "/n" &lt;&lt; "/n/t";
  
                          std::cout &lt;&lt; "Choose 1 for Yes and 2 for No" &lt;&lt; "/n" &lt;&lt; "/n";
  
          std::cin &gt;&gt; userInput;
  
      } while (userInput == 1);
  
      system("pause");
  
      return 0;
  }
  </code></pre>