我有一個abstract
Base
類和Derived
類。刪除運算符和數組?
int main()
{
Base *arrayPtr[3];
for (int i = 0; i < 3; i++)
{
arrayPtr[i] = new Derived();
}
//some functions here
delete[] arrayPtr;
return 0;
}
我不知道如何使用刪除操作符。如果我刪除了如上所示的基類指針數組,這個調用派生類對象析構函數並清理內存?
+1虛擬析構點 – 2010-01-06 11:29:28
不需要在數組上調用delete [],它是不是'newed'。 – fretje 2010-01-06 11:30:43
是的,當你編寫你的評論時,我正在編輯我的答案,thx – 2010-01-06 11:31:54