title: Errors when compiling complex number class in c++
body: <p>I have code that is supposed to show addition, subtraction, etc. of complex numbers with no input from the user necessary. I have three classes: test.cpp, complex.cpp, and complex.h to run the program, define the constructors and methods, and create a header class respectively. However, when I run my code I get a series of errors that I've been trying to figure out for a while now.</p>
  
  <p>complex.h</p>
  
  <pre><code>//complex class definition
  #ifndef COMPLEX_H
  #define COMPLEX_H
  
  
  //class complex
  class Complex
  {
  public:
      Complex(); //default no arg constructor
      Complex(double a); //one arg constructor
      Complex(double a, double b); //two arg constructor
      Complex operator+(const Complex &amp;) const; //addition method
      Complex operator-(const Complex &amp;) const; //subtraction method
      Complex operator*(const Complex &amp;) const; //multiplication method
      Complex operator/(const Complex &amp;) const; //division method
      void print() const; //output
  private:
      double a; //real number
      double b; //imaginary number
  }; //end class Complex
  
  #endif
  </code></pre>
  
  <p>complex.cpp</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include "complex.h"
  using namespace std;
  
  //no arg constructor
  Complex::Complex()
  {
      a = 0;
      b = 0;
  }
  
  //one arg instructor
  Complex::Complex(double real)
  {
      a = real;
      b = 0;
  }
  
  //two arg constructor
  Complex::Complex(double real, double imaginary)
  {
      a = real;
      b = imaginary;
  }
  
  //addition
  Complex Complex::operator+(const Complex &amp;number2) const
  {
      return a + number2.a, b + number2.b;
  }
  
  //subtraction
  Complex Complex::operator-(const Complex &amp;number2) const
  {
      return a - number2.a, b - number2.b;
  }
  
  //multiplication
  Complex Complex::operator*(const Complex &amp;number2) const
  {
      return a * number2.a, b * number2.b;
  }
  
  //division
  Complex Complex::operator/(const Complex &amp;number2) const
  {
      return a / number2.a, b / number2.b;
  }
  
  //output display for complex number
  void Complex::print() const
  {
      cout &lt;&lt; '(' &lt;&lt; a &lt;&lt; ", " &lt;&lt; b &lt;&lt; ')';
  }
  </code></pre>
  
  <p>test.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;complex&gt;
  #include "complex.h"
  #include "stdafx.h"
  using namespace std;
  
  int main()
  {
      Complex b(1.0, 0.0);
      Complex c(3.0, -1.0);
  
      /*cout &lt;&lt; "a: ";
      a.print();
  
      system ("PAUSE");*/
  
  };
  </code></pre>
  
  <p>In test right now as the code shows the lower parts are commented out and I have attempted to only call two of the three constructors to see if I can get any of this working.</p>
  
  <p>The errors I receive:</p>
  
  <pre><code>    error C2065: 'Complex' : undeclared identifier
      error C2065: 'Complex' : undeclared identifier
      error C2146: syntax error : missing ';' before identifier 'b'
      error C2146: syntax error : missing ';' before identifier 'c'
      error C3861: 'b': identifier not found  
      error C3861: 'c': identifier not found
  </code></pre>
  
  <p>I am trying to run this in Visual Studio 2010. Can someone please help?</p>