Hi, I am trying to make a “Named Vector” that I can use in TFile::Add and retrieve by name later. TVectorD only inherit from TObject, not from TNamed, so they only have the fixed name “TVectorT”, and I lose track of which vector is which in the TFile.
If I try to do this:
class NamedVectorD : public TNamed, public TVectorD
{
ClassDef(NamedVectorD,1);
using TNamed::TNamed; // Requires C++11
virtual ~NamedVectorD(){};
};
then I get a bunch of errors about implicit instantiation:
root [0] .L Utility.C+
Info in <TMacOSXSystem::ACLiC>: creating shared library /Users/jfcaron/Projects/Proto2BeamTest2/./Utility_C.so
In file included from /Users/jfcaron/Projects/Proto2BeamTest2/Utility_C_ACLiC_dict.cxx:17:
In file included from /Users/jfcaron/Projects/Proto2BeamTest2/Utility_C_ACLiC_dict.h:34:
/Users/jfcaron/Projects/Proto2BeamTest2/./Utility.C:156:46: error: implicit
instantiation of undefined template 'TVectorT<double>'
class NamedVectorD : public TNamed, public TVectorD
^
/Users/jfcaron/Software/custom_root/compiled/include/root/TVectorDfwd.h:24:31: note:
template is declared here
template<class Element> class TVectorT;
^
/Users/jfcaron/Projects/Proto2BeamTest2/Utility_C_ACLiC_dict.cxx:282:15: error:
cannot initialize object parameter of type 'TNamed' with an expression of type
'Utility::NamedVectorD'
TNamed::ShowMembers(R__insp);
^~~~~~~~~~~
2 errors generated.
If I change the TVectorD to a TArrayD, then there is no such error. I am guessing this is because TArrayD isn’t a template specialization of some TArray, but is instead a daughter class of TArray. TVectorD is a template specialization of TVectorT, not a child of it. Now I thought that since TVectorD was a typedef and I can #include “TVectorD.h”, that I would never actually have to deal with the fact that it uses templates. But here clearly the difference matters.
Is there some simple modification to my class that I could make that would allow it to inherit from TNamed and TVectorD? I’d rather not make my class a templated NamedVector, I’m ok with only using the version of TVector.
I could use the TArrayD version but then I’d have to convert from/to actual TVectorDs before/after writing to the TFile. It’s not that big of a problem, but I’d rather avoid it.
Jean-François