看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) gcc 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 結構初始化問題 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) 正確版:http://ideone.com/jb3AQP 錯誤版:http://ideone.com/VEUexX 這兩個code,差別在於錯誤版是struct 後, 直接給一個結構變數start, 然後再設定start這個初始值, 但是compiler以後卻不能過,這是為什麼? 因為把初始值(14、15行)拿掉後,又可以compiler。 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 203.73.48.51 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1415465585.A.2C6.html
LPH66: 正確版 #14 這是宣告時直接初始化, 這時允許這種語法 11/09 01:06
LPH66: 錯誤版在 #11 已宣告變數, 在那之後的 = 便不是初始化了 11/09 01:06
lantw44: 錯誤版那個 要寫成 (struct time){12, 32, 25.49} 才對 11/09 01:34
LPH66: 嗯, 不過技術上來說這是做出另一個 struct time 再指定給 11/09 01:55
LPH66: start 就是了 11/09 01:55
Push5F: http://ideone.com/e.js/1UVmqO ? 11/09 02:58
suhorng: http://ideone.com/levWb9 code一字未改(逃 11/09 14:00
dirkc: c++11的aggregate init+copy assign;原理還是如一二樓說的 11/09 20:44
dirkc: 我是回樓上非回原po;原po應該是c吧 11/09 20:51