complex::complex
Erstellt eine komplexe Zahl aus den angegebenen reellen und imaginären Teilen oder eine Kopie einer anderen komplexen Zahl.
constexpr complex(
const T& RealVal = 0,
const T& ImagVal = 0
);
constexpr complex( const complex& );
template<class Other>
constexpr complex(
const complex<Other>& ComplexNum
);
Parameter
RealVal
Der Wert des reellen Teils, der zum Initialisieren der zu erstellenden komplexen Zahl verwendet wird.ImagVal
Der Wert des imaginären Teils, der zum Initialisieren der zu erstellenden komplexen Zahl verwendet wird.ComplexNum
Die komplexe Zahl, deren reelle und imaginäre Teile zum Initialisieren der zu erstellenden komplexen Zahl verwendet werden.
Hinweise
Der erste Konstruktor initialisiert den gespeicherten reellen Teil in RealVal und den gespeicherten imaginären Teil in ImagVal. Der zweite Konstruktor initialisiert den gespeicherten reellen Teil in ComplexNum**.real**() und den gespeicherten imaginären Teil in ComplexNum**.imag**().
In dieser Implementierung wird, falls ein Konvertierungsprogramm Memberfunktionen der Vorlage nicht unterstützt, die Vorlage:
template<class Other>
complex(const complex<Other>& right);
durch Folgendes ersetzt:
complex(const complex& right);
Hierbei handelt es sich um den Kopierkonstruktor.
Beispiel
// complex_complex.cpp
// compile with: /EHsc
#include <complex>
#include <iostream>
int main( )
{
using namespace std;
double pi = 3.14159265359;
// The first constructor specifies real & imaginary parts
complex <double> c1 ( 4.0 , 5.0 );
cout << "Specifying initial real & imaginary parts,"
<< "c1 = " << c1 << endl;
// The second constructor initializes values of the real &
// imaginary parts using those of another complex number
complex <double> c2 ( c1 );
cout << "Initializing with the real and imaginary parts of c1,"
<< " c2 = " << c2 << endl;
// Complex numbers can be initialized in polar form
// but will be stored in Cartesian form
complex <double> c3 ( polar ( sqrt( (double)8 ) , pi / 4 ) );
cout << "c3 = polar ( sqrt ( 8 ) , pi / 4 ) = " << c3 << endl;
// The modulus and argument of a complex number can be recovered
double absc3 = abs ( c3 );
double argc3 = arg ( c3 );
cout << "The modulus of c3 is recovered from c3 using: abs ( c3 ) = "
<< absc3 << endl;
cout << "Argument of c3 is recovered from c3 using:\n arg ( c3 ) = "
<< argc3 << " radians, which is " << argc3 * 180 / pi
<< " degrees." << endl;
}
Ausgabe
Specifying initial real & imaginary parts,c1 = (4,5)
Initializing with the real and imaginary parts of c1, c2 = (4,5)
c3 = polar ( sqrt ( 8 ) , pi / 4 ) = (2,2)
The modulus of c3 is recovered from c3 using: abs ( c3 ) = 2.82843
Argument of c3 is recovered from c3 using:
arg ( c3 ) = 0.785398 radians, which is 45 degrees.
Anforderungen
Header: <complex>
Namespace: std