Hi,
a few weeks ago, I told you about a problem in defining a template class
in root using cint. I still have this problem even with the new version of
root and rootcint (root 3.00/06, cint 5.14.79, these versions was supposed
to support the things I want to do).
This is the code I want to use is below and is OK in standard C++. The
compilation reads :
/opt/root/bin/rootcint -f cintDict.cc -c test.h LinkDef.h
and the error is :
Error: No symbol Type1_x in current scope FILE:test.h LINE:14
Syntax error FILE:test.h LINE:18
Warning: Unknown type Type1 in function argument FILE:test.h LINE:18
Syntax error FILE:test.h LINE:33
Warning: Unknown type Type1 in function argument FILE:test.h LINE:33
Warning: Error occured during reading source files
Warning: Error occured during dictionary source generation
!!!Removing cintDict.cc cintDict.h !!!
/opt/root/bin/rootcint: error loading headers...
make: *** [cintDict.cc] Error 1
What am I doing wrong ???
Thanks !
-------------- test.h ------------------------------------------
#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:
Test(Type x=0){_x=x;}
~Test(){};
template<class Type1> Test(const Test<Type1>& t1);
Type GetX() const {return _x;}
ClassDefT(Test<Type>,0)
};
ClassDefT2(Test,Type)
ClassImpT(Test,Type)
template<class Type> template<class Type1>
Test<Type>::Test(const Test<Type1>& x1)
: _x(static_cast<Type>(x1.GetX()))
{
}
#endif
------------ LinkDef.h -------------------------------------
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class Test<float>;
#pragma link C++ class Test<int>;
#pragma link C++ class Test<double>;
#endif
--------------- Makefile --------------------------------
ROOTCFLAGS = $(shell root-config --cflags)
ROOTLIBS = $(shell root-config --libs)
ROOTGLIBS = $(shell root-config --glibs)
ROOTCINT = $(ROOTSYS)/bin/rootcint
# Linux with egcs
CXX = g++
CXXFLAGS = -g -O -Wall -fPIC
CXXFLAGS += $(ROOTCFLAGS)
LIBS = $(ROOTLIBS)
GLIBS = $(ROOTGLIBS)
OBJECTS= cintDict.o main.o
all: main
clean:
rm -f *.o cintDict.*
cintDict.cc: test.h LinkDef.h
$(ROOTCINT) -f $@ -c $^
.o.cc:
$(CXX) -c $< $(CXXFLAGS)
main: $(OBJECTS)
$(CXX) $(CXXFLAGS) $(LIBS) $(GLIBS) $(OBJECTS) -o $@
------------------ main.cc ----------------------------------
#include <TRandom.h>
#include <cmath>
#include <math.h>
#include <iostream>
#include "test.h"
using namespace std;
TROOT root ("hello", "Hello World");
int main (int argc, char ** argv)
{
Test<int> test(1);
Test<double> p(test);
return 0;
}
-----------------------------------------------------------
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:40 MET