Hi Toshi, the Root3 definition of TObject::IsEqual is virtual Bool_t IsEqual(const TObject* obj) const (see http://root.cern.ch/root/html/TObject.html). As you didn't give the const specifiers your IsEqual doesn't get called as it does not replace the TObject::IsEqual. This "const" change was introduced in Vers 3, so for 2.xx your method works. Cheers, Axel. > -----Original Message----- > From: owner-roottalk@pcroot.cern.ch > [mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Toshinori Abe > Sent: Monday, February 19, 2001 12:28 PM > To: roottalk@pcroot.cern.ch > Subject: [ROOT] question about TMap.FindObject > > > Dear Rooters, > > I have a question about TMap. > When I try to run the attached file, I got different answers > using root version 2.25/03 and 3.00/05. > > with Version 2.25/03 > fa=0x3cdb98 a=0x3cdb48 amc=0x3bf500 val=0x3bf500 > fb=0x3cdb98 b=0x3cdb70 bmc=0x3bf520 val=0x3bf500 > > with Version 3.00/05 > fa=4d4520 a=4d1e38 amc=4d1e50 val=4d1e50 > fb=4d4540 b=4d1e68 bmc=4d1e80 val=4d1e80 > > I thought two outputs of "val" would be same. > It looks that "MyObject.IsEqual" does not work in "TMap" for root 3.00/05. > Would you suggest me if any idea? > > Thanks very much in advance, - Toshi > > > Name : Toshinori Abe > Add. : SLAC M/S 96, 2575 SandHill Road, Menlo Park, CA 94025, USA > E-mail : toshi@SLAC.Stanford.EDU > ---------------------------------------------------------------------- > > > #include <iostream.h> > > #include "TROOT.h" > #include "TMap.h" > #include "TMath.h" > #include "TObject.h" > > class MyObject : public TObject { > private: > Int_t m_ID; > public: > MyObject(Int_t ID) {m_ID=ID;} > MyObject() {m_ID=0;} > ~MyObject(){} > Int_t GetID() {return m_ID;} > ULong_t Hash(){ return m_ID;} > Bool_t IsEqual(TObject *obj){ return m_ID == ((MyObject*)obj)->GetID();} > }; > > TMap *MyList = new TMap( 17, 0 ); > > int main (int argc,char* argv[]) { > > TROOT simple( "Test", "MyObject test" ); > > MyObject* a=new MyObject(1); TObject* amc=new TObject(); > MyObject* b=new MyObject(1); TObject* bmc=new TObject(); > MyList->Add(a,amc); > MyList->Add(b,bmc); > > cout<<"fa="<<MyList->FindObject(a)<<" a="<<a<<" amc="<<amc<< > " val="<<MyList->GetValue(a)<<endl; > cout<<"fb="<<MyList->FindObject(b)<<" b="<<b<<" bmc="<<bmc<< > " val="<<MyList->GetValue(b)<<endl; > > return 0; > } > > >
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:36 MET