Adding a template class with non-type parameters

dear all,
I’m trying to add a template class which is defined like this:
(MyClass.h)

template<class A, class B, UInt_t C> 
class MyClass : 
public TObject
{
   ....
pivate:
   A a;
   B b[C];

   ClassDefT(MyClass, 1);
};
ClassDef3T2(MyClass, A, B, C);

(MyClass.cxx)

ClassImp3T(MyClass, A, B, C);
....

MyClassLinkDef.h

#ifdec __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class MyClass<TObject, TObject, [what here?]>+
#endif

MyClass.cxx compiles without errors, but I do not how to manage the LinkDef file because I have a non-type parameter.
Could you help me, please?

Many thanks
Roberto

Hi,

you will have to provide a value for the third parameter.

The template is only fully specified if all the template arguments are specified. CINT cannot call functions or create / store / manage objects otherwise, because the type is not defined without it. It just shows that templates are a huge overhead for what you are trying to achieve (if the UInt_t really is an array dimension). It is a lot better, in any standards, not just CINT or ROOT, to use a dynamic structure like vectors. You can still preallocate them, you can still do bounds checking, and in the end you have almost the same performance with no code bloat.

Axel.

ok, fine… now it compiles

Unfortunately I still have a little problem. What I’m trying to do is to create a shared library usging this kind of object… I can create it, but I get an error while loading the library…
I do not understand if I am doing something wrong somewhere (actually to me it looks ok).
could you, please have a look into my (attached) code?
I attach only LinkDef and .h files

roberto
AliTOFMonitorObjectData.h (1.64 KB)
AliTOFMonitorObject.h (4.22 KB)
TOFMonitorLinkDef.h (468 Bytes)

Hi,
what’s the error you get?
Axel.

dlopen error: /home/preghenella/SOFT/MONITOR/libTOFMonitor/lib/libTOFMonitor.so: undefined symbol: _ZN19AliTOFMonitorObjectI23AliTOFMonitorObjectData7TObjectLj5EEC1Ev
Load Error: Failed to load Dynamic link library /home/preghenella/SOFT/MONITOR/libTOFMonitor/lib/libTOFMonitor.so
*** Interpreter error recovered ***

Hi,

$ echo _ZN19AliTOFMonitorObjectI23AliTOFMonitorObjectData7TObjectLj5EEC1Ev | c++filt AliTOFMonitorObject<AliTOFMonitorObjectData, TObject, 5u>::AliTOFMonitorObject()
Did you implement that function?

Cheers, Axel.

actually I implemented the generic constructor like this

template<class DataType, class ChildType, UInt_t ChildNumber> AliTOFMonitorObject<DataType, ChildType, ChildNumber>::AliTOFMonitorObject()

(complete .cxx attached)

Do I have to implement everything for every possible template instance? (I hope no)
AliTOFMonitorObject.cxx (3.81 KB)

Hi,

When instantiating a specific template instance the C++ compile must have access to the complete set of member functions.

In practice that meant that when dealing with template you either:

  1. Include all implementation in the header files (sometimes the header in split in 2 files a .h file and .icc file).

OR

  1. have some of the implementatin in a .cxx AND explicitly instantiate the complete set of template instantiation you want.

Seemingly you want to use the first.

Cheers,
Philippe