→ Killercat: 誒,要14喔 XD 我以為這東西是11的 06/01 23:23
→ Killercat: 另外我一時眼殘看錯 拍寫 XD 06/01 23:24
※ 編輯: LPH66 (180.177.29.238), 06/01/2017 23:24:57
→ LPH66: literal suffix 在 11 就有了, 但 ""s 是 14 才有 06/01 23:25
→ LPH66: 11 沒有定義標準的 literal suffix 06/01 23:26
推 ROGZ: 感謝您的解答 06/01 23:50
→ ROGZ: 但雖然說是Copy Initialization,但試著寫一下Copy Construc 06/01 23:52
→ ROGZ: tor和overload assignment operator後,卻發現它都沒有使用 06/01 23:54
→ ROGZ: 到,所以原則上來說A a = string("123")和A a("123")是執行 06/01 23:57
→ ROGZ: 類似的動作去construct A吧 06/01 23:58
→ ROGZ: 但是,A a("123")能把"123"視為string,而A a = string("123 06/02 00:02
→ ROGZ: ")卻只能視為const char* 06/02 00:02
→ ROGZ: 上面寫錯了,應該是A a = "123",被視為const char* 06/02 00:07
→ djshen: 不是視為string 是implicit conversion 06/02 00:20
→ djshen: en.cppreference.com/w/cpp/language/copy_initialization 06/02 00:24
→ djshen: 有提到the implicit conversion in copy-initialization 06/02 00:24
→ djshen: must produce T directly from the initializer 06/02 00:24
→ djshen: 還有The equals sign, =, in copy-initialization of a 06/02 00:25
→ djshen: named variable is not related to the assignment 06/02 00:25
→ djshen: operator 06/02 00:25
→ ROGZ: 感謝djshen大的資料,有比較了解了 06/02 00:29
→ hunandy14: 同問 int i=0; 與 int i(0); 前者也是有複製? 06/02 00:49
→ hunandy14: 在C上後者並不能這樣寫 06/02 00:50
→ hunandy14: 是否只在 C++ 才具 copy init 在 C 是 D init? 06/02 00:51
→ hunandy14: 或是 兩者都是 copy init 06/02 00:51
推 steve1012: 用=會呼叫copy constructor. C沒有研究但c沒有construc 06/02 01:22
→ steve1012: tor 吧 06/02 01:22
→ djshen: built-in type就直接standard conversion了吧? 06/02 01:36
推 steve1012: 對耶是int 06/02 03:27
推 boy770329: A="123"在有支援copy elision的compiler是不會做copy 06/02 08:04
→ boy770329: 的吧 06/02 08:04
→ LPH66: > 沒有呼叫 ctor 的問題 06/02 10:06
→ LPH66: 這就是為什麼我原文加了個 (至少語意上) 的括號 06/02 10:07
→ LPH66: 因為這裡是標準允許實作可以不 copy 的地方 06/02 10:07
→ LPH66: (即是所謂的 copy elision) 06/02 10:07
→ LPH66: 當要 copy 的來源物件是個剛生成的物件時 06/02 10:08
→ LPH66: 標準允許這裡跳過一次複製讓那物件在複製目的地直接生成 06/02 10:09
→ james1022jk: ctor在單一引數時有一些規則 06/02 11:16
→ loveflames: 函數返回也有一樣的問題 06/02 11:58
→ hunandy14: 了解~感謝 06/03 14:15