#include "TH1.h" #include #include #include int main() { std::vector HistList; std::vector HistName{"a","b","c","d","e"}; for (auto name: HistName) { TH1F hist(name.c_str(),"test",100,-3,3); hist.FillRandom("gaus",10000); HistList.push_back(hist); } std::vector HistPtrList; for (auto hist: HistList) { HistPtrList.push_back(&hist); std::cout << hist.GetMaximumBin() << std::endl; // It gives the correct number } for (auto histptr: HistPtrList) { std::cout << histptr->GetMaximumBin() << std::endl; // It gives some random huge number and it seems that the histograms are not there anymore. } }