Address of a pointer or pointer to std::vector?


I used to do like this to set a branch with std::vector:
std::vector * v = new std::vector();

instead of :
std::vector * v = new std::vector();

Are both ways suppose to behave in the same way ? They seem to give the same results…is it still safe to use the former way ?

Thanks !

Hi Bertrand,

Yes both are now supported (for writing), in addition you can also usestd::vector<double> v; mytree->Branch("v",&v);


PS. When using std::vector *v; and mytree->Branch(“v”,v); note that no change in the value of v will be reflected in the TTree. I.e.std::vector<double> *v = new std::vector; mytree->Branch("v",v); mytree->Fill(); delete v; v = new std::vector; mytree->Fill(); // => This [b]will[/b] crash since mytree is still using the deleted vector.