cplusplus.com
C++ : Reference : Miscellaneous : complex : complex : complex
 
cplusplus.com
Information
Documentation
Reference
Articles
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Miscellaneous
complex
exception
functional
iterator
limits
locale
memory
new
numeric
stdexcept
typeinfo
utility
valarray
complex
abs
arg
complex
conj
cos
cosh
exp
imag
log
log10
norm
polar
pow
real
sin
sinh
sqrt
tan
tanh
complex
complex::complex
complex operators
member functions:
complex::imag
complex::real
member types:
complex::value_type


complex::complex

public member function
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:

(2,2)