complex - STL C++

operator/()

Declaration

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

Description

This friend function is the overloaded division operator for the complex class. This operator returns the quotient of kqrZ1 and kqrZ2. Two overloaded versions allow us to calculate the quotient of a complex number and 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 << "Quotient 1 = " << (qZ1 / qZ2) << endl;
	cout << "Quotient 2 = " << (qZ1 / dReal) << endl;
	cout << "Quotient 3 = " << (dReal / qZ2) << endl;

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

Output

operator/() Output
 

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