Name
complex class template — Complex number template
Synopsis
template<typename T> class complex { public: typedef T value_type; complex(const T& re = T( ), const T& im = T( )); complex(const complex& z); template<typename X> complex(const complex<X>& z); T real( ) const; T imag( ) const; complex& operator= (const T& x); complex& operator+=(const T& x); complex& operator-=(const T& x); complex& operator*=(const T& x); complex& operator/=(const T& x); complex& operator=(const complex& z); template<typename X> complex& operator= (const complex<X>& z); template<typename X> complex& operator+=(const complex<X>& z); template<typename X> complex& operator-=(const complex<X>& z); template<typename X> complex& operator*=(const complex<X>& z); template<typename X> complex& operator/=(const complex<X>& z); };
The complex
class template
represents a complex number. The <complex>
header specializes the
template for the float
, double
, and long
double
types. You can instantiate complex<>
for any type that behaves
in the manner of the fundamental numeric types.
The type definition is a straightforward representation of a complex number. Basic assignment operators are defined as member functions, and arithmetic operators are defined as global functions.
template<typename X>
complex
(const complex<X>& z)
Constructs a
complex<T>
object by copying the members fromz
. Effectively, this converts a complex object instantiated for one type to acomplex
object of another type.T
real
( ) const
Returns the ...
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.