Dear all,
I am using GCC 4.8.2 to compile on Ubuntu 14.04. I have had a look at the ownership issues, but it still puzzles me why the following expressions give a segmentation violation (even on v5.34.18):
What I thought was the most thoughtful :
TFile file("filename.root");
h = new TH1D(*dynamic_cast<TH1D*>(file.Get("hsit")))
(I didn’t expect this one to work but…) :
TFile file("filename.root");
h = new TH1D(*static_cast<TH1D*>(file.Get("hsit")))
Heap allocation and dynamic cast fail (I doesn’t make sense to me) :
TFile* file("filename.root");
h = new TH1D(*dynamic_cast<TH1D*>(file->Get("hsit")))
Ownership trick and dynamic cast :
TDirectory* CurrentDir = gDirectory;
TFile file("filename.root");
h = new TH1D(*dynamic_cast<TH1D*>(file.Get("hsit")))
CurrentDir->cd();
And why only these tricks work:
Heap allocation and static cast :
TFile* file("filename.root");
h = new TH1D(*static_cast<TH1D*>(file->Get("hsit")))
Ownership trick and static cast :
TDirectory* CurrentDir = gDirectory;
TFile file("filename.root");
h = new TH1D(*static_cast<TH1D*>(file.Get("hsit")))
CurrentDir->cd();
Thanks in advance,
Valérian