C++ Syntax: delete

Description

The delete operator destroys an object that has been created by new when passed a pointer to the object. For example:-
TH2F *H_TDC = new TH2F("H_TDC","TDCA vs TDCB",100,0.,600.,100,0.,600.);

...

delete H_TDC;
delete first calls the object's termination routine (i.e. its destructor) and then releases the space the object occupied on the heap memory. If an array of objects was created using new, then delete must be told that it is dealing with an array by preceding the name with an empty []:-
Int_t *my_ints = new Int_t[10];

...

delete []my_ints;
This tells the delete operator to go and find the array size, and delete all the objects.

See operator precedence

Other Uses for delete

None.

Usage Notes

None.
Go Back to the The C++ Crib Top Page


If you have any comments about this page please send them to Nick West