title: implementing complex number power function in c++?
body: <p>Like the title said, i'm trying to implement an operator^(int n) which will calculate a complex number to the nth power. I know that <code>this</code> is a pointer that point to the current class object so i came up with this code:</p>
  
  <pre><code>    class Complex{
      protected:
        float a,b;
      public:
        Complex() {a=0;b=0;}
        Complex(float x, float y){a=x;b=y;}
        void set(float x, float y){a=x;b=y;}
        Complex operator*(Complex C){
                  Complex temp;
                  temp.a=a*C.a-b*C.b;
                  temp.b=a*C.b+b*C.a;
                  return temp;
        }
        Complex operator^(int n){
                  Complex ONE=Complex(1,0);
                  if (n&lt;=0) return ONE;
                  return ((*this)*((*this)^(n-1)));
        }
        void Display(){
                  cout&lt;&lt;a&lt;&lt;' '&lt;&lt;b&lt;&lt;endl;
        }
        };
        int main() {
            Complex C;
            C.set(2,0);
            C=C^3;
            C.Display();
        }
  </code></pre>
  
  <p>The C.Display() is supposed to print <code>8 0</code> but when i ran in eclipse it display <code>2 0</code>. Please tell me why this happens. Also really appreciate if anyone could tell me how to make <code>ONE</code> at line 15 a constant class object like BigInteger.ONE in Java.</p>