complex::operator=
將數字加入至目標複數,數字指定可能複雜或型別相同指派複數的實數及虛數部分。
template<class Other>
complex<Type>& operator=(
const complex<Other>& _Right
);
complex<Type>& operator=(
const Type& _Right
);
參數
- _Right
複數或與目標複數的參數相同的數字。
傳回值
指定為參數所指定的數字的複數。
備註
作業的多載,以便簡單算術運算可以執行,但不包含任何資料轉換為特定格式。
範例
// complex_op_as.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> assigned to type complex<double>
complex <double> cl1 ( 3.0 , 4.0 );
complex <double> cr1 ( 2.0 , -1.0 );
cout << "The left-side complex number is cl1 = " << cl1 << endl;
cout << "The right-side complex number is cr1 = " << cr1 << endl;
cl1 = cr1;
cout << "The complex number cr1 assigned to the complex number cl1 is:"
<< "\n cl1 = cr1 = " << cl1 << endl;
// Example of the second member function
// type double assigned to type complex<double>
complex <double> cl2 ( -2 , 4 );
double cr2 =5.0;
cout << "The left-side complex number is cl2 = " << cl2 << endl;
cout << "The right-side complex number is cr2 = " << cr2 << endl;
cl2 = cr2;
cout << "The complex number cr2 assigned to the complex number cl2 is:"
<< "\n cl2 = cr2 = " << cl2 << endl;
cl2 = complex<double>(3.0, 4.0);
cout << "The complex number (3, 4) assigned to the complex number cl2 is:"
<< "\n cl2 = " << cl2 << endl;
}
需求
標題: <複雜>
命名空間: std