I am getting 6 errors in my code. This is my first code on Operator Overloading in OOPS. I am getting undefined reference Complex :: Complex(double, double). Plz help me in fixing the error. Here is my code :
//header file "Complex.h"
ifndef COMPLEX_H_INCLUDED
define COMPLEX_H_INCLUDED
include<iostream>
using namespace std;
class Complex { friend ostream &operator<<(ostream &, const Complex &); friend istream &operator>>(istream &, Complex &);
public:
Complex(const Complex &);
~Complex();
Complex(double = 0.0, double = 0.0);
Complex operator+(const Complex &) const;
Complex operator-(const Complex &) const;
Complex operator*(const Complex &) const;
private:
double real;
double img;
};
endif // COMPLEX_H_INCLUDED
//Header file "Complex1.h"
ifndef COMPLEX1_H_INCLUDED
define COMPLEX1_H_INCLUDED
include<iomanip>
include"Complex.h"
using namespace std;
Complex :: Complex(const Complex &c1) : real(c1.real), img(c1.img) {
} Complex :: ~Complex() {
}
Complex Complex :: operator+(const Complex &right) const { Complex c3;
c3.real = real + right.real;
c3.img = img + right.img;
return c3;
}
Complex Complex :: operator-(const Complex &right) const { Complex c3;
c3.real = real - right.real;
c3.img = img - right.img;
return c3;
}
Complex Complex :: operator*(const Complex &right) const { Complex c3;
c3.real = real * right.real - img * right.img;
c3.img = real * right.img + img * right.real;
return c3;
}
istream &operator>>(istream &input, Complex &c1) { input>>c1.real; input>>c1.img;
return input;
}
ostream &operator<<(ostream &output, const Complex &c2) { output<<setw(7)<<c2.real; output<<setw(7)<<c2.img;
return output;
}
endif // COMPLEX1_H_INCLUDED
include"Complex1.h"
using namespace std;
int main() { Complex c1; Complex c2; Complex c3, c4, c5, c6;
cout<<"\nENTER c1 = "<<c1;
cout<<"\nENTER c2 = "<<c2;
c3 = c1 + c2;
c4 = c1 - c2;
c5 = c1 * c2;
cout<<"\nBEFORE INTIALISATION c6: "<<c6;
cout<<"\nENTER c6 = ";
cin>>c6;
Complex c7(c6);
cout<<"\nc3 = "<<c3;
cout<<"\nc4 = "<<c4;
cout<<"\nc5 = "<<c5;
cout<<"\nc6 = "<<c6;
cout<<"\nc7 = "<<c7;
}