This is a program that will process complex numbers (real and imaginary), but I'm getting an Internal Compiler Error:
Code:
#include <iostream>
using namespace std;
class Complex
{
double real, img;
public:
Complex( double realval = 0.0, double imagval = 0.0 ) : real(realval), img(imagval)
{
} // default contructor
Complex( const Complex &right )
{
real = right.real;
img = right.img;
} // copy constructor
friend Complex operator+( const Complex & left, const Complex &right );
friend ostream &operator<<( ostream &output, const Complex &right );
};
Complex operator+(const Complex &left, const Complex &right )
{
return Complex(left.real+right.real, left.img+right.img);
}
ostream &operator<<( ostream &output, const Complex &right )
{
return output << "(" << right.real << ") + (" << right.img << ")i";
}
int main()
{
Complex A(2.5,-2.2), B(5.0,1.0), C;
C = A + B;
cout << "A is first complex number: " << A << endl;
cout << "B is second complex number: " << B << endl;
cout << "C is A + B: " << C << endl;
return 0;
}