I'm working on this complex function to multiply two complex numbers. A and B are not in the scope of the overloaded function. How do I get the function to read them; do I have to make a separate getFunction()?
Code:
#include <iostream>
using namespace std;
class Complex
{
private:
double real;
double img;
public:
Complex( double realPart = 0.0, double imagPart = 0.0 ) : real(realPart), img(imagPart)
{
} // default constructor
~Complex(); // destructor
friend Complex operator*( const Complex &left, const Complex &right );
friend ostream &operator<<( ostream &output, const Complex &right );
bool operator!() const; // is entry empty? ***
}; // end class Complex
Complex operator*( const Complex &left, const Complex &right )
{
Complex tmp;
tmp.real = A.real * B.real - A.img * B.img;
tmp.img = A.real * B.img + B.real * A.img;
cout << "C is A * B: " << tmp << "i" << endl;
// return tmp;
}
ostream &operator<<( ostream &output, const Complex &right )
{
return output << "(" << right.real << ") + (" << right.img << ")i";
}
bool Complex::operator !() const // is the entry empty?
{
cout << "Invalid entry." << endl;
real == 0.0;
img == 0.0;
}
Complex::~Complex()
{
}
int main()
{
Complex A(-2.5,2.0), B(5.2,1.0), C;
C = A * B;
return 0;
}