以前,我有以下代碼。是否有任何需要分配空指針std :: auto_ptr
double* a[100];
for (int i = 0; i < 100; i++) {
// Initialize.
a[i] = 0;
}
的a
0初始化數組的目的是,當我反覆刪除a
元素,一切都將正常工作,甚至還沒有仍然分配給的a
元素記憶。
for (int i = 0; i < 100; i++) {
// Fine.
delete a[i];
}
現在,我想利用auto_ptr,避免手動調用刪除。
std::auto_ptr<double> a[100];
for (int i = 0; i < 100; i++) {
// Initialize. Is there any need for me to do so still?
a[i] = std::auto_ptr<double>(0);
}
我想知道,是否有任何需要我來初始化auto_ptr
持有空指針?我的感覺不是。我只想確認一下,這樣就沒有任何障礙。
也許你可以解釋爲什麼你想要一個指針數組在第一位加倍。將它改爲'auto_ptr'的數組聽起來像是它缺少真正的問題。 –
2010-09-08 02:26:18