This is a discussion on Multiplying overloaded operator within the C++ Programming forums, part of the General Programming Boards category; I'm working on this complex function to multiply two complex numbers. A and B are not in the scope of ...

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;
}```

2. Didn't you mean
Code:
```Complex operator*( const Complex &left, const Complex &right )
{
Complex tmp;
tmp.real = left.real * right.real - left.img * right.img;
tmp.img = left.real * right.img + left.real * right.img;
cout << "C is A * B: " << tmp << "i" << endl;
return tmp;
}```
Kurt

3. Well ha! I tried that initially, but had a couple of them switched, so I wasn't getting the correct result. Thanks much for your time Kurt!