complex::complex
建構複雜數值與指定的虛擬路徑和虛構區段或做為其他複數的複本。
complex(
const Type& _RealVal = 0,
const Type& _ImagVal = 0
);
template<class Other>
complex(
const complex<Other>& _ComplexNum
);
參數
_RealVal
用來實內部的值初始化建構的複數。_ImagVal
用於的虛數區段中的值初始化建構的複數。_ComplexNum
虛擬和虛構區段可用來初始化建構的這個複數的複數。
備註
第一個建構函式會將這個預存的內部實 _RealVal 和儲存的虛構區段會 _Imagval。第二個建構函式會將這個預存的內部實 _ComplexNum**.real**() 和儲存的虛構區段會 _ComplexNum**.imag**()。
在這個實作,則為,如果轉譯器不支援成員樣板函式,範本:
template<class Other>
complex(const complex<Other>& right);
將取代為:
complex(const complex& right);
無論哪一個複製建構函式。
範例
// 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;
}
Output
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.
需求
標題: <complex>
命名空間: std