Hi Heather,
see my comments below
Rene Brun
Heather Kelly wrote:
>
> Hi,
>
> I know this is just my ignorance... but I am trying to include a map inside
> a ROOT class and I am running into trouble. My search through roottalk has
> not provided me with enough details...seeing a full example would probably
> solve my problem - so if someone has some code they are willing to share -
> it would be greatly appreciated.
>
> I am using Root 3.02.07 on Windows.
>
> I have a class, which contains a map:
>
> class MyClass: public TObject {
>
> public:
> MyClass();
>
> ~MyClass();
>
> private:
> std::map<McParticle*,Double_t> m_energyItem;
>
> ClassDef(MyClass,1)
> };
>
> Where McParticle is itself a class derived from TObject.
>
> In my MyLinkDef.h file I have:
>
> #ifdef __CINT__
>
> #pragma link off all globals;
> #pragma link off all classes;
> #pragma link off all functions;
>
> #pragma link C++ class McParticle+;
> #pragma link C++ class map<McParticle*, Double_t>-!; //<======REMOVE THIS LINE
> #pragma link C++ class MyClass+;
>
> #endif
>
> Right now I get compiler errors, starting with:
> mcRootDataCint.h(62) : error C2143: syntax error : missing ';' before '<'
> for this line:
> /* STUB derived class for protected member access */
> typedef map<McParticle*,double,less<McParticle*>,allocator<double> >
> G__maplEMcParticlemUcOdoublecOlesslEMcParticlemUgRcOallocatorlEdoublegRsPgR;
>
These messages will disappear if you remove the line from LinkDef.h
> Some questions:
> Would it be better to use double, rather than Double_t as the second type
> in the map? Does it matter?
>
It does not matter
> In the pragma statement, of the MyLinkDef.h file, I used "-!", per an
> example I saw in an old roottalk message... I also tried "!". It seems to
> me that I should allow the Streamer() method to be generated - as I thought
> it was no longer necessary to write your own streamer for relatively simple
> STL classes. Am I correct in assuming that it is not possible to use "+"
> with an STL class?
>
Yes, you can use "+" for STL classes or templated classes in general.
> Do I need to add anything else to the MyLinkDef.h file to make this work?
>
> Is it possible to use a typedef in my ROOT class to create more simple name
> for the map? Will that cause trouble for rootcint? Originally, I was
> using such a typedef, but removed it once I started to have trouble.
>
Yes, you can use a typedef
> Is there something I can read to tell me how to do this correctly?
>
See example using STL in $ROOTSYS/test/bench.cxx, TBench.h
> Thank you,
> Heather
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:48 MET