int New int (5);
The new operation is actually made up of two steps:
(1) Configure the required memory with the appropriate new operator function entity.
Call the new operator in the function library.
int New sizeof int ) );
(2) Set an initial value for the configured object.
5;
Initialization should be performed only after the memory configuration succeeds (via the new operator).
1 int *pi; 2 3 if sizeof (int))) 4 5 5 // In two steps
In a similar way;
Delete Pi; if 0 ) __delete (pi);
Note that pi is not automatically cleared 0 (NULL).
So if you have the following actions:
if 5 ( ) { //...}
will be legal (but unpredictable).
Delete Ends the life of the object that the pi points to, so it should not be processed later.
When new is working on a class:
New Point3D;
is converted to:
Point3D *origin; // Pseudo Code if sizeof = Point3D::P Oint3d (Origin);
Deep Exploration C + + object model notes (1)--new and delete operators