Hi Ingo, The output of your few lines should produce: Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated Adress of mydatabase: 0x86a5050 Adress of mydatabase2: 0x86a0440 Instead of calling the constructor directly, we recommend the form: TDatabasePDG *pdg = TDatabasePDG::Instance(); Rene Brun Ingo Strauch wrote: > > Hi Rooters! > > If I understand correctly, TDatabasePDG is supposed to protect itself against > multiple instances: > > ---------------------------------------------------------------------------- > TDatabasePDG::TDatabasePDG() : TNamed("PDGDB","The PDG particle data base") > { > // Create PDG database. > > fParticleList = 0; > if (fgInstance) Warning("TDatabasePDG", "object already instantiated"); > else fgInstance = this; > } > ---------------------------------------------------------------------------- > > But compiling the following code does not give me the above warning I would > expect. > > ---------------------------------------------------------------------------- > #include<iostream.h> > #include<TROOT.h> > #include<TDatabasePDG.h> > > int main() > { > TROOT root("PDGtest", "How about multiple instances?"); > TDatabasePDG *mydatabase; > TDatabasePDG *mydatabase2; > mydatabase = new TDatabasePDG(); > mydatabase2 = new TDatabasePDG(); > cout << "Adress of mydatabase: " << mydatabase <<endl; > cout << "Adress of mydatabase2: " << mydatabase2 <<endl; > > } > > ---------------------------------------------------------------------------- > > Do I miss something??? And isn't the constructor supposed to be non-public > (Singleton pattern by Gamma etc.)? > > Ciao, > Ingo > > ---------------------------------------------------------------------------- > Ingo Strauch Budapester Str. 30, 20359 Hamburg, Tel.: +49 40 7421 4722 > Office: DESY, Group H1/AAC1, Room 1c354, Notkestr. 85, 22607 Hamburg > strauch@mail.desy.de Tel. +49 40 8998 2312 > http://www-h1.desy.de/~strauch/ FAX +49 40 8998 4385 > I. Phys. Institut RWTH Aachen, Room 28B210, Sommerfeldstr. 14, 52056 Aachen > strauch@toots.physik.rwth-aachen.de Tel. +49 241 80 7183 > http://www-users.rwth-aachen.de/Ingo.Strauch/ FAX. +49 241 8888 661 > ----------------------------------------------------------------------------
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:20 MET