complex - STL C++

operator*()

Declaration

complex<X> operator*(const complex<X>& kqrZ1, const complex<X>& kqrZ2);

Description

This friend function is the overloaded multiplication operator for the complex class. This operator returns the product of kqrZ1 and kqrZ2. Two overloaded versions allow a complex number to be multiplied by the real number parameter type.

Header Include

#include <complex>

Overloads

complex<X> operator*(const complex<X>& kqrZ, const X& kxrX);

complex<X> operator*(const X& kxrX, const complex<X>& kqrZ);

Example

#include <complex>
#include <iostream>

int main()
{
	using namespace std;

	// Create two complex numbers
	complex<double> qZ1(2.0, 4.0);
	complex<double> qZ2(1.3, 5.1);
	cout << "Complex Number 1 : "<< qZ1 << endl;
	cout << "Complex Number 2 : "<< qZ2 << endl;

	// Try each version of the operator*
	double dReal = 3.14;
	cout << "Product 1 = " << (qZ1 * qZ2) << endl;
	cout << "Product 2 = " << (qZ1 * dReal) << endl;
	cout << "Product 3 = " << (dReal * qZ2) << endl;

	// Keep the window open
	cin.get();
	return 0;
}

Output

operator*() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.