ClassDef and templates

Hi,

I’m wrote a template class and followed the instructions in Chapter 15 of the users’ guide. Therefore, the header contains:

The implementation file has:

Finally in the linkdef file I added the line:

Upon compiling I received the following error.

[quote]include/DataSetPlotter.hh: In member function ‘virtual TClass* Flux::DataSetPlotter::IsA() const’:
include/DataSetPlotter.hh:126: error: ‘template class Flux::DataSetPlotter’ used without template parameters
include/DataSetPlotter.hh: In member function ‘void Flux::DataSetPlotter::StreamerNVirtual(TBuffer&)’:
include/DataSetPlotter.hh:126: error: ‘template class Flux::DataSetPlotter’ used without template parameters[/quote]

Where line 126 contains the ClassDef macro.

Perhaps somewhat naively I tried the obvious fix and replaced Classdef statement with:

Now the code compiles and links fine, but I’m concerned that the problem isn’t really fixed, and I have just masked the underlying issue with a fudge. Is the definition in the manual incomplete or is this a compiler related problem?

Cheers,

Hugh

Hi,

The ClassDef should be:ClassDef(DataSetPlotter, 0 );

Cheers,
Philippe.

Works a treat! Thanks.

By the way, should the argument for ClassImp() macro include the namespace?

Yes the ClassImp argument should include the namespace. This is due to the fact that ClassDef is placed ‘inside’ the scope of the class template while the ClassImp is (and should be) outside of that scope.

Cheers,
Philippe.

Of course! Makes perfect sense when it’s explained to you!