#include <iostream>
using namespace std;
class Multiply {
public:
double real;
double imag;
Multiply(double r = 0, double i = 0) {
real = r;
imag = i;
}
void print() {
}
};
Multiply operator*(Multiply co1, Multiply co2) {
Multiply temp;
temp.real = (co1.real * co2.real) + (co1.imag * co2.imag);
temp.imag = (co1.imag * co2.real) + (co2.imag * co1.real);
return temp;
}
int main()
{
Multiply com1(1.1, 2.2), com2(3.3, 4.4), total1, total2;
total1 = operator*(com1, com2);
cout << "real = " << total1.real << " " << "image = " << total1.imag << endl;
total2 = com1 * com2;
cout << "real = " << total2.real << " " << "image = " << total2.imag << endl;
return 0;
}
结果为