I’m sure this has been asked many times already, however I didn’t find the answer in the forum, nor in the “Object Ownership” guide. So here we go. This code segfaults, as soon as the second function tries to draw the histogram.
I compile this code using .x foo.cpp+. I need this histogram in many places in my code but I don’t like the idea of having global TFiles. I thought the h->SetDirectory(0) would do the job…
void DebugFilescope()
{
TH2D* h = openHist();
h->Draw();
}[/code]
To my surprise, it even works without the cloning detour. Initially I wanted to open many files in the same function, and to return many histograms. Am I supposed to return an array of pointers in this case, rather than having given pointers filled?