public member function
<complex>
complex (const T& re = T(), const T& im = T());
complex (const complex& cmplx);
template<class X>
complex (const complex<X>& cmplx);
Complex number constructor
Constructs a
complex object.
It may be constructed from two values (
re and
im) or from another complex number.
Parameters
- re, im
- Real and imaginary parts, respectively, of complex number.
T is complex's template type.
- cmplx
- A complex object.
If constructed from a complex object with a different template parameter (X), the apropriate conversions are performed.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// complex constructor example
#include <iostream>
#include <complex>
using namespace std;
int main ()
{
complex<double> first (2.0,2.0);
complex<double> second (first);
complex<long double> third (second);
cout << third;
return 0;
}
|
Output: