共用方式為


operator+ (<complex>)

將兩個複數,或兩者都可能屬於型別的子集實數及虛數一。

template<class Type> 
   complex<Type> operator+( 
      const complex<Type>& _Left, 
      const complex<Type>& _Right 
   ); 
template<class Type> 
   complex<Type> operator+( 
      const complex<Type>& _Left, 
      const Type& _Right 
   ); 
template<class Type> 
   complex<Type> operator+( 
      const Type& _Left, 
      const complex<Type>& _Right 
   ); 
template<class Type> 
   complex<Type> operator+( 
      const complex<Type>& _Left 
   );

參數

  • _Left
    是複數的參數型別由加入 + 作業的第一個複數或數字。

  • _Right
    是複數的參數型別由加入 + 作業的第二個複數或數字。

傳回值

這個複數由值和型別的參數輸入指定兩個數字的加法運算。

備註

作業的多載,以便簡單算術運算可以執行,但不包含任何資料轉換為特定格式。 一元運算子會傳回 _Left.。

範例

// complex_op_add.cpp
// compile with: /EHsc
#include <complex>
#include <iostream>

int main( )
{
   using namespace std;
   double pi = 3.14159265359;

   // Example of the first member function
   // type complex<double> plus type complex<double>
   complex <double> cl1 ( 3.0 , 4.0 );
   complex <double> cr1 ( 2.0 , 5.0 );
   complex <double> cs1 = cl1 + cr1;

   cout << "The left-side complex number is cl1 = " << cl1 << endl;
   cout << "The right-side complex number is cr1 = " << cr1 << endl;
   cout << "The sum of the two complex numbers is: cs1 = " << cs1 << endl;
   double abscs1 = abs ( cs1 );
   double argcs1 = arg ( cs1 );
   cout << "The modulus of cs1 is: " << abscs1 << endl;
   cout << "The argument of cs1 is: "<< argcs1 << " radians, which is " 
        << argcs1 * 180 / pi << " degrees." << endl << endl; 

   // Example of the second member function
   // type complex<double> plus type double
   complex <double> cl2 ( 3.0 , 4.0 );
   double cr2 =5.0;
   complex <double> cs2 = cl2 + cr2;

   cout << "The left-side complex number is cl2 = " << cl2 << endl;
   cout << "The right-side complex number is cr2 = " << cr2 << endl;
   cout << "The sum of the two complex numbers is: cs2 = " << cs2 << endl;
   double abscs2 = abs ( cs2 );
   double argcs2 = arg ( cs2 );
   cout << "The modulus of cs2 is: " << abscs2 << endl;
   cout << "The argument of cs2 is: "<< argcs2 << " radians, which is " 
        << argcs2 * 180 / pi << " degrees." << endl << endl;

   // Example of the third member function
   // type double plus type complex<double>
   double cl3 = 5.0;
   complex <double> cr3 ( 3.0 , 4.0 );
   complex <double> cs3 = cl3 + cr3;

   cout << "The left-side complex number is cl3 = " << cl3 << endl;
   cout << "The right-side complex number is cr3 = " << cr3 << endl;
   cout << "The sum of the two complex numbers is: cs3 = " << cs3 << endl;
   double abscs3 = abs ( cs3 );
   double argcs3 = arg ( cs3 );
   cout << "The modulus of cs3 is: " << abscs3 << endl;
   cout << "The argument of cs3 is: "<< argcs3 << " radians, which is " 
        << argcs3 * 180 / pi << " degrees." << endl << endl; 

   // Example of the fourth member function
   // plus type complex<double>
   complex <double> cr4 ( 3.0 , 4.0 );
   complex <double> cs4 = + cr4;

   cout << "The right-side complex number is cr4 = " << cr4 << endl;
   cout << "The result of the unary application of + to the right-side"
        << "\n complex number is: cs4 = " << cs4 << endl;
   double abscs4 = abs ( cs4 );
   double argcs4 = arg ( cs4 );
   cout << "The modulus of cs4 is: " << abscs4 << endl;
   cout << "The argument of cs4 is: "<< argcs4 << " radians, which is " 
        << argcs4 * 180 / pi << " degrees." << endl << endl;  
}
  

需求

標題: <複雜>

命名空間: std