看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC++ 問題(Question): 寫出來的加法每次都無法進行 餵入的資料(Input): 兩個數字 123456 123456 預期的正確結果(Expected Output): 246912 錯誤結果(Wrong Output): 似乎是out of range 不過我百思不得其解 程式碼(Code):(請善用置底文網頁, 記得排版) http://ideone.com/GaHpy 我有寫一些備註 ------------------------------------------------------ 更新 這是我的 HugeInteger.cpp http://ideone.com/nRoDA 這是我的HugeInteger.h http://ideone.com/7mLDC -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.132.83.187
PkmX:if(i=0) 12/25 00:40
PkmX: ^ 12/25 00:40
什麼意思?? 我放了一個if的原因是因為要是到了最左邊還大於十的話就會溢位了 ※ 編輯: steve1012 來自: 220.132.83.187 (12/25 00:43)
purincess:意思就是i會變成0 然後if永遠執行else的部分 12/25 00:45
PkmX:=是assignment,==才是判斷相等 12/25 00:45
啊我蠢了 竟然忘記了 不過這樣還是不能跑耶 我打一下error message 他說 Debug Assertion Failed ... ... ... _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) ※ 編輯: steve1012 來自: 220.132.83.187 (12/25 00:49) 然後我有看過compiler好像每次都是在 for( int i = IntegerSize-1 ; i >=0 ;i--)這行錯掉 另外補充一下我存大數的陣列長度是IntegerSize(預設40)
loveme00835:free 了不該 free 的東西.. 12/25 00:51
可是我沒有用到Free耶 只有在destructor的時候delete了我宣告的陣列 我在原文補充了我整個class ※ 編輯: steve1012 來自: 220.132.83.187 (12/25 00:54)
PkmX:我猜應該是你沒寫copy constructor的問題 12/25 01:06
真的.. 太強了! ※ 編輯: steve1012 來自: 114.34.202.142 (12/25 11:01)