[ROOT] confusion about templates

From: Brandon Kohn (blk@maia-institute.org)
Date: Fri Jan 18 2002 - 13:29:44 MET


HI Guys,

I'm trying to do some template stuff with root (basically just want the
autodocs to document my template class), but I'm having trouble finding a
definitive how-to or faq on using templates with root.  The part that I'm
fuzzy on is how or where to place template instantiations to correspond with
the ones in the linkdef:

i.e.

#ifdef __CINT__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ class LD_Template_Array<int>-;
#pragma link C++ class LD_Template_Vector<int>-;

#endif

Now I have to instantiate LD_Template_Array<int> somewhere right?

As it stands, here is the error I get when compiling the dictionary created
with the above linkdef:

NeutralDictionary.cpp(89) : error C2143: syntax error : missing ';' before
'<'
NeutralDictionary.cpp(89) : error C2373: '>>' : redefinition; different type
modifiers
NeutralDictionary.cpp(89) : error C2530: '>>' : references must be
initialized
NeutralDictionary.cpp(89) : error C2143: syntax error : missing ';' before
'<'
NeutralDictionary.cpp(90) : error C2143: syntax error : missing ';' before
'{'
NeutralDictionary.cpp(90) : error C2447: missing function header (old-style
formal list?)
NeutralDictionary.cpp(98) : error C2143: syntax error : missing ';' before
'<'
NeutralDictionary.cpp(98) : error C2373: '>>' : redefinition; different type
modifiers
NeutralDictionary.cpp(98) : error C2530: '>>' : references must be
initialized
NeutralDictionary.cpp(98) : error C2143: syntax error : missing ';' before
'<'
NeutralDictionary.cpp(99) : error C2143: syntax error : missing ';' before
'{'
NeutralDictionary.cpp(99) : error C2447: missing function header (old-style
formal list?)

And here is the code where the errors are occuring in the Dictionary file:

template <> TBuffer &operator>><int >(TBuffer &buf, LD_Template_Array<int>
*&obj)
{
   // Read a pointer to an object of class LD_Template_Array<int>.

   ::Error("LD_Template_Array<int>::operator>>", "objects not inheriting
from TObject need a specialized operator>> function"); if (obj) { }
   return buf;
}

//__________________________________________________________________________
____
template <> TBuffer &operator>><int >(TBuffer &buf, LD_Template_Vector<int>
*&obj)
{
   // Read a pointer to an object of class LD_Template_Vector<int>.

   ::Error("LD_Template_Vector<int>::operator>>", "objects not inheriting
from TObject need a specialized operator>> function"); if (obj) { }
   return buf;
}


Also, I can avoid this problem by placing an ! with the - option in the lindef, but I'm still curious about what is causing it.

Hope this is a good enough description, and thanks in advance for any help.

Brandon Kohn
+377 97 97 41 51 ext. 306 (Work)
+377 97 77 86 71 (Home)
blk@maia-institute.org
The Maia Institute, Monaco



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:38 MET