看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) Linux 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) gcc 問題(Question): 我想要實作一struct 的 vector 但行數21~22與行數49行會互相排斥,把其中之一comment掉就不會有error 可是我兩個都需要。 程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔) https://pastebin.com/PUpj2iym 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.114.218.69 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1527434016.A.B29.html
jerryh001: 需要一個data的default constructor 05/27 23:21
ken32293355: 感謝你,是因為 string的size是未知嗎?所以它resize 05/27 23:31
ken32293355: 不知道要給多少記憶體 05/27 23:31
ken32293355: 好像不是這個原因,我好困惑 05/27 23:40
jerryh001: resize會用default建立物件 可是你寫了自己的ctor 所以 05/27 23:59
jerryh001: default(隱藏)的ctor就被蓋掉了 要自己補回來 05/27 23:59
idiont: 你沒寫constructor 他會自動幫你產生default constructor 05/28 00:02
idiont: 但是你寫了constructor 他就不會產生default constructor 05/28 00:02
ken32293355: 我懂了,謝謝你們 05/28 02:02