[問題] 簡單的destructor但bug很怪

看板C_and_CPP作者 (nikeasyanzi)時間10年前 (2013/10/27 03:07), 編輯推噓1(105)
留言6則, 3人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) codeblock + 內建GCC 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 莫名奇妙死在destructor 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式直接當掉 程式碼(Code):(請善用置底文網頁, 記得排版) http://paste.ideaslabs.com/show/uqhmNazTis 補充說明(Supplement): 就只是個初學者練習constructor & destructor 的程式罷了 單純檢查input array length 然後動態產生陣列 但好像都死在destructor 死在line 67 因為還能看到line 66的輸出 但line 69的輸出看不到 不知如何解釋 也不知如何debug起@@ 懇請版上先進指教 -- CyberPanel 5000CP 換 NT.500 http://myurl.com.tw/05bd EmailCash 5000e 換 NT.500 http://myurl.com.tw/rgdq -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.251.220.213 ※ 編輯: nikeasyanzi 來自: 111.251.220.213 (10/27 03:08)

10/27 03:30, , 1F
60行 arr_ptr=new int(leng);
10/27 03:30, 1F

10/27 03:33, , 2F
多想一下這行哪裡錯了
10/27 03:33, 2F

10/27 09:08, , 3F
new陣列 vs new單一並給初始值
10/27 09:08, 3F

10/27 13:20, , 4F
感謝樓上兩位 一語驚醒夢中人 只差在()& []
10/27 13:20, 4F

10/27 13:22, , 5F
new 陣列: arrptr=new int[arr_leng]
10/27 13:22, 5F

10/27 13:24, , 6F
new單一並給初值: arr_ptr=new int(leng);
10/27 13:24, 6F
文章代碼(AID): #1IR1Bku8 (C_and_CPP)