complex - STL C++

complex<X>::operator-=()

Declaration

complex<X>& complex<X>::operator-=(const complex<X>& kqrZ);

Description

This is the operator-=() function for the complex number class template. This operator assigns the left-hand side complex number the value of itself minus the right-hand side, which is kqrZ. For the overloaded versions, the left-hand side is assigned to be the difference of itself with a real number of the value kxrX or the difference of itself with a complex number of a different parameter type, kqrDiff."

Header Include

#include <complex>

Overloads

complex<X>& complex<X>::operator-=(const X& kxrX);

complex<X>& complex<X>::operator-=(const complex<Y>& kqrDiff);

Example

#include <complex>
#include <iostream>

int main()
{
	using namespace std;

	// Create a complex number
	complex<double> qZ(2.0, 4.0);
	cout << "Complex Number : "<< qZ << endl;

	// Create a second complex number and assign it
	complex<double> qZ2(.2, .3);
	qZ -= qZ2;
	cout << "After the first assigment : "<< qZ << endl;

	// Make a second assignment to a "real" number
	qZ -= 3.14;
	cout << "After the second assigment : "<< qZ << endl;

	// Make a third assignment with a different type
	complex<float> qFloatZ(2.0, 1.0);
	qZ -= qFloatZ;
	cout << "After the third assigment : "<< qZ << endl;

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

Output

complex<X>::operator-=() Output
 

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