Dear George,
I modified your header file and made it work.
Try following with t328.h and t328.cxx.
$ cint t328.cxx
$ makecint -mk makefile -dl t328.dll -H t328.h
$ make -f makefile
$ cint t328.cxx
The first cint-run interprets the template. Second cint-run
uses compied template function for int and double version.
You can not precompile template itself. This is a C++ limitation.
You can only precompile instantiated template.
]
Thank you
Masaharu Goto
// t328.h ///////////////////////////////////////////
#include <stdio.h>
typedef bool Bool_t;
template <class X>
Bool_t TestTemplate(const X& t) {
size_t a = sizeof(X);
printf("%d\n",a);
return(true);
}
#ifdef __MAKECINT__
Bool_t TestTemplate(const int& t) ;
Bool_t TestTemplate(const double& t) ;
#endif
// t328.cxx ////////////////////////////////////
#include "t328.h"
#pragma include_noerr "t328.dll"
class b {
double d;
int a;
};
main() {
int x;
double d;
b y;
TestTemplate(x);
TestTemplate(x);
TestTemplate(d);
TestTemplate(d);
TestTemplate(y);
}
///////////////////////////////////////////////////////
>
>Rooters,
>
>I'm trying to explore what I can and can't do with templates in CINT,
>since I would like to use some of their features in ROOT programs. I've
>managed to get template classes linked in (with the small problem of
>the Streamer functions, but Masa says that that's been fixed in the
>newest CINT). And, I know that template member functions are not
>supported (which is a shame, but I'll deal). However, I couldn't for
>the life of me get an ordinary template function to get recognized by
>CINT. I had a little piece of code like this to test:
>
>#include "Rtypes.h"
>
>template <class X>
>Bool_t TestTemplate(const X &t) {
> size_t a = sizeof(X);
> printf("%d\n",&a);
>}
>
>I tried to .x and .L this piece of code (figuring CINT would force me
>to always interpret the code, but that's okay with me for some
>functions anyway); this gave me a segvio in root (version 2.23.10). I
>tried to link it into CINT using:
>
>#pragme link C++ function TestTemplate*;
>
>but that failed, with it being unable to find the function. I tried
>instantiating a version explicitly in the file, but then CINT
>complained about not supporting partial template specialization.
>
>So, am I going about this completely wrong? Is there a way to get this
>to work?
>
>George Heintzelman
>gah@bnl.gov
>
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:17 MET