title: Overloading Multiplication Operator
body: <p>I am working on an assignment for my c++ class. We are having to overload several operators such as +, -, !=, =, etc. Well, I have all of them figured out except the multiplication. Everything I have tried gives an overflow or just doesn't compile. Not sure what I need for it. </p>
  
  <p>Here is the header file that holds my overloads.</p>
  
  <pre><code>#ifndef COMPLEXNUMBER_H
  #define COMPLEXNUMBER_H
  #include&lt;iostream&gt;
  using namespace std;
  
  class ComplexNumber{
  public:
  
      double real, imaginary;
      ComplexNumber(){
          real = 0;
          imaginary = 0;
      }
      ComplexNumber(double a, double b){
          real = a;
          imaginary = b;
      }
      ComplexNumber(double a){
  
          real = a;
          imaginary = 0;
  
      }
  
      ComplexNumber &amp; operator= (const ComplexNumber &amp; rhs){
  
          if(this == &amp;rhs){
  
              return *this;
  
          }
          else{
  
              real = rhs.imaginary;
              imaginary = rhs.imaginary;
          }
  
          return *this;
      }
  
      ComplexNumber &amp; operator+= (const ComplexNumber &amp;rhs){
  
          real += rhs.real;
          imaginary += rhs.imaginary;
          return *this;
  
      }
  
      ComplexNumber &amp; operator-= (const ComplexNumber &amp;rhs){
  
          real -= rhs.real;
          imaginary -= rhs.imaginary;
          return *this;
  
      }
  
      const ComplexNumber operator+ (const ComplexNumber &amp;rhs){
  
          ComplexNumber result = *this;
          result += rhs;
          return result;
  
      }
  
      const ComplexNumber operator- (const ComplexNumber &amp;rhs){
  
          ComplexNumber result = *this;
          result -= rhs;
          return result;
  
      }
  
      const ComplexNumber operator* (const ComplexNumber &amp;rhs){
  
          return *this * rhs;
  
      }
  
      friend ostream &amp; operator&lt;&lt; (ostream &amp;out, const ComplexNumber &amp;c){
  
          out &lt;&lt; "(" &lt;&lt; c.real &lt;&lt; (c.imaginary&lt;0?" - ":" + ") &lt;&lt; abs(c.imaginary) &lt;&lt; " i)";
          return out;
  
      }
  
      friend istream &amp; operator&gt;&gt; (istream &amp; in, ComplexNumber &amp;c){
  
          in &gt;&gt; c.real &gt;&gt; c.imaginary;
          return in;
  
      }
  
      operator double(){
  
          return real;
  
      }
  
      bool operator== (const ComplexNumber &amp; rhs) const {
  
          bool result = (this-&gt;real == rhs.real) &amp;&amp; (this-&gt;imaginary == rhs.imaginary);
          return result;
  
      }
  
      bool operator!= (const ComplexNumber &amp;rhs) const{
  
          return !(*this == rhs);
  
      }
  };
  
  #endif
  </code></pre>
  
  <p>I know that multiplication operator is way off, but its just what I have at the moment. Here it is on its own. Any ideas would be greatly appreciated!!</p>
  
  <pre><code>const ComplexNumber operator* (const ComplexNumber &amp;rhs){
  
              return *this * rhs;
  
          }
  </code></pre>