Hi Benoit,
here is a correct version of you example:
//---------------------- test.h
#ifndef TEST_H
#define TEST_H
#include <iostream>
#include <TObject.h>
using namespace std;
template<class Type> class Test : public TObject {
private:
Type _x;
public:
void Print(){cout << _x << endl;}
Test(){};
Test(Type x){_x=x;}
~Test(){};
ClassDefT(Test<Type>,0)
};
ClassDefT2(Test,Type)
#endif
//-------------------- test.cxx
#include "test.h"
ClassImpT(Test,Type)
// explicit template instantiation of the version specified in LinkDef.h
template Test<int>;
//-------------------- LinkDef.h
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class Test<int>;
#endif
//-------------------- Build and execute
$ rootcint -f testDict.cxx -c test.h LinkDef.h
$ g++ -g -fPIC `root-config --cflags` -c test.cxx
$ g++ -g -fPIC `root-config --cflags` -c testDict.cxx
$ g++ -shared -o libTest.so test.o testDict.o
$ root
root [0] gSystem->Load("libTest.so");
root [1] Test<int> t(10)
root [2] t.Print()
10
Cheers, Fons.
Benoit Revenu wrote:
>
> Hi,
>
> I'm trying to add a template class in ROOT using cint but with no succes.
> I had a look at the roottalk but I couldn't find any satisfactory answer.
> Where can I find a complete correct example for that ?
>
> For information, here is my code:
>
> test.h file :
> ---------------------------------------
> #ifndef TEST_H
> #define TEST_H
>
> #include <iostream>
> #include "root.h"
>
> using namespace std;
>
> template<class Type> class Test : public TObject
> {
>
> private:
>
> Type _x;
>
> public:
>
>
> void Print(){cout << _x << endl;}
> Test(){};
> Test(Type x){_x=x;}
> ~Test(){};
> ClassDef(Test,0)
>
> };
>
> #endif
--
Org: CERN, European Laboratory for Particle Physics.
Mail: 1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch Phone: +41 22 7679248
WWW: http://root.cern.ch/~rdm/ Fax: +41 22 7677910
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:36 MET