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 right-hand side number, which is kqrZ. For the overloaded version, the left-hand side is assigned to be a real number with the value kxrX.

Header Include

#include <complex>

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(5.2, 1.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;

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

Output

complex<X>::operator=() Output
 

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