使用删除
具有 删除运算符的两个语法变体:一个对象的和其他+一些的对象。 下面的代码片段演示这些如何不同:
// expre_Using_delete.cpp
struct UDType
{
};
int main()
{
// Allocate a user-defined object, UDObject, and an object
// of type double on the free store using the
// new operator.
UDType *UDObject = new UDType;
double *dObject = new double;
// Delete the two objects.
delete UDObject;
delete dObject;
// Allocate an array of user-defined objects on the
// free store using the new operator.
UDType (*UDArr)[7] = new UDType[5][7];
// Use the array syntax to delete the array of objects.
delete [] UDArr;
}
下面两个用例数未定义的结果:使用删除 (删除的数组形式 []) 在对象并使用删除的 nonarray 窗体在数组中。