看板 C_and_CPP 關於我們 聯絡資訊
※ 引述《cation234 (貓離子)》之銘言: : 在下找到了這個 說明了為什麼會有這種問題 : : http://www-h.eng.cam.ac.uk/help/tpl/languages/C++/complex.html 那裡面有幾句話不對。 "In fact, c2=(3,7) is equivalent to c2=3,7. C++'s "," operator suppresses the value of the first operand in favour of the second, so c2=3,7 is equivalent to c2=7." 當寫成 c2=(3,7); 時, c2 會變成 7, 而 3 是多餘的,沒效果。 但寫成 c2=3,7; 時, c2 會變成 3, 而 7 是多餘的,沒效果。 請自行實驗看看。 至於其道理,則是 comma operator 比 assignment operator 的優先權 還要低。 c2=3,7; 等同於 (c2=3), 7; : : : 以下是小弟的code, 簡單的測試C++ STL的複數資料型態: : : : #include <iostream> : : : #include <complex> : : : using namespace std; : : : int main() : : : { : : : complex <double> x = (0.1, 0.2); : : ~~~~~~~~~~~這里的結果是0.2 : : : complex <double> mu = (0.2, 0.6); : : ~~~~~~~~~~~這個是0.6 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.130.208.168