C++ Syntax: new
TH2F *H_TDC = new TH2F("H_TDC","TDCA vs TDCB",100,0.,600.,100,0.,600.);
creates a
TH2F
histogram object. new first allocate space for the object on the heap
and then calls the object's initialisation routine
(i.e. its constructor).
As the above example shows, arguments can be supplied to the constructor by
supplying them after the
class
name.
An
array
of objects can be created using new:-
Int_t *my_ints = new Int_t[10];although in this case, only the default constructor, i.e. the constructor to be called when no arguments, can be used.
In order to avoid memory leaks the delete operator must be called once the object is no longer needed.
See operator precedence