{ TFile *file = new TFile("demo.root","recreate"); TH1F *h = new TH1F("hwoow","test",1000,-2,2); h->FillRandom("gaus"); //h->Write(); file->WriteObject(h,"h9585"); file->Close(); file->Open("demo.root"); //TFile:: if(!file->IsZombie()){ TH1F *h2=(TH1F*) file->Get("h9585"); cout << "Test session started ******************************" << endl; cout << "Name : " << h2->GetName() << endl; cout << "Npars : " << h2->GetNdivisions() << endl; file->Close(); } } /* bash-3.2$ root writeROOT.C ******************************************* * * * W E L C O M E to R O O T * * * * Version 5.25/02 29 September 2009 * * * * You are welcome to visit our Web site * * http://root.cern.ch * * * ******************************************* ROOT 5.25/02 (trunk@30530, Sep 29 2009, 15:28:19 on linuxx8664gcc) CINT/ROOT C/C++ Interpreter version 5.17.00, Dec 21, 2008 Type ? for help. Commands must be C++ statements. Enclose multiple statements between { }. root [0] Processing writeROOT.C... Test session started ****************************** Error: illegal pointer to class object h2 0x0 502 writeROOT.C:17: */