看板 EE_DSnP 關於我們 聯絡資訊
※ 引述《flarehunter (Range)》之銘言: : 在constructor那邊 : 大小有預設n = 0 : 這是代表把_capacity設為0嗎? : 那如果後面要變大 : 乘以二還是0耶… : 是不是要改成 預設n = 1啊 : 然後 要不要寫個解構子把 _data 的空間free掉? Good question. 題目沒講清楚. 這是參照 STL vector 的規格, 也就是說 array 的 default constructor will set both the size and capacity to 0. When the first element is added in (pushed back), the capacity will become 1 or 2, depending on the platform, and the size will be 1, of course. You can decide the new capacity = 1 or 2, or use debugger to see how vector is handled in your computer. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.121.132.121