Re: [問題] 大數字加法
※ 引述《steve1012 (steve)》之銘言:
: → PkmX:我猜應該是你沒寫copy constructor的問題 12/25 01:06
HugeInteger HugeInteger::Add( HugeInteger num2 )
{
HugeInteger temporary;
...
return temporary;
}
這一行會隱含 copy construction。
temporary 在這個 function 結束之後就 destruct 了,
所以實質上會有另一個 compiler 自行加上的 temp 物件,相當於這樣:
HugeInteger compiler_added_temp(temporary);
temporary.~HugeInteger();
return compiler_added_temp;
因為沒有實作 copy contructor,預設的 copy contructor 是把 data member
逐一複製,於是 compiler_added_temp.IntegerArr == temporary.IntegerArr,
所以該陣列會被 delete 兩次。
題外話,你的程式碼變數/functon命名原則很凌亂...。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.250.29.121
※ 編輯: freesamael 來自: 111.250.29.121 (12/25 04:36)
推
12/25 11:02, , 1F
12/25 11:02, 1F
→
12/25 11:03, , 2F
12/25 11:03, 2F
→
12/25 11:04, , 3F
12/25 11:04, 3F
→
12/25 11:04, , 4F
12/25 11:04, 4F
→
12/25 11:05, , 5F
12/25 11:05, 5F
→
12/25 11:05, , 6F
12/25 11:05, 6F
→
12/25 11:35, , 7F
12/25 11:35, 7F
→
12/25 15:12, , 8F
12/25 15:12, 8F
→
12/25 15:13, , 9F
12/25 15:13, 9F
→
12/25 15:14, , 10F
12/25 15:14, 10F
→
12/25 15:14, , 11F
12/25 15:14, 11F
→
12/25 16:54, , 12F
12/25 16:54, 12F
→
12/25 16:55, , 13F
12/25 16:55, 13F
→
12/25 16:55, , 14F
12/25 16:55, 14F
→
12/25 16:56, , 15F
12/25 16:56, 15F
→
12/25 16:56, , 16F
12/25 16:56, 16F
→
12/25 17:01, , 17F
12/25 17:01, 17F
推
12/25 17:52, , 18F
12/25 17:52, 18F
→
12/25 17:52, , 19F
12/25 17:52, 19F
→
12/25 17:53, , 20F
12/25 17:53, 20F
推
12/25 22:30, , 21F
12/25 22:30, 21F
討論串 (同標題文章)