※ 引述《lex0606 (shawn)》之銘言:
: //爬文后還是沒有說明如何在C++中
: //給定2個實數值在1個複數變數中 初值的設定
: //以下是測試過的程式
: int main(int argc, char* argv[])
: {
: complex <double> x = (0.1, 0.2);
: complex <double> mu = (0.2, 0.6);
: cout<<"x = "<<x<<endl;
: cout<<"mu = "<<mu<<endl<<endl;
: //以上是原文初始值設定的問題
: //以下是修正原文初始值設定的問題
: complex <double> y = std::complex <double> (0.1, 0.2);
: complex <double> nu = std::complex <double> (0.2, 0.6);
你的問題其實這樣就行了:
complex <double> z (0.1, 0.2);
complex <double> psi (0,2, 0.6);
不用寫 = 而且和你後來寫的(y和nu)是一樣的意思 都是使用 constructor 來設初值
因此這裡的 , 就變成 constructor 呼叫(函式呼叫)中參數的分隔
而非 comma operator 了
--
'Oh, Harry, dont't you see?' Hermione breathed. 'If she could have done
one thing to make absolutely sure that every single person in this school
will read your interview, it was banning it!'
---'Harry Potter and the order of the phoenix', P513
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.28.92