次の方法で共有


complex::complex

指定した実際という部分を使用したり、他の複素数のコピーとして複素数を構築します。

complex(
    const Type& _RealVal = 0, 
    const Type& _ImagVal = 0
);

template<class Other>
   complex(
      const complex<Other>& _ComplexNum
   );

パラメーター

  • _RealVal
    構築される複素数の初期化に使われる実数部の値。

  • _ImagVal
    構築される複素数の初期化に使われるイメージ部分の値。

  • _ComplexNum
    構築される複素数を初期化するために実際という部分が使用される複素数。

解説

一つ目のコンストラクターは、格納されている _RealVal 実数部と _Imagval に格納されたイメージ部分を初期化します。2 つ目のコンストラクターは、_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;
}

出力

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

参照

関連項目

complex Class