RE: [ROOT] Class Template Definition

From: Philippe Canal (pcanal@fnal.gov)
Date: Thu Dec 12 2002 - 16:10:15 MET


Hi Silvia,

You need to either make TChannel a class template or select which
instantiation of TOptional your TChannel should use.

In other word, either

class TChannel : public TObject {
		TOptional<int> *opt;
};

or

template <class T> class TChannel : public TObject {
		TOptional<int> *opt;
};

Also note that in ROOT 3.03.09 and above, ClassDefT can be replace by
ClassDefT and
ClassDefT2 is not necessary anymore.

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Silvia Eccher
(Iannone)
Sent: Thursday, December 12, 2002 8:57 AM
To: roottalk@pcroot.cern.ch
Subject: [ROOT] Class Template Definition


Dear rooters,
I nedd to define a class (TChannel) containing a TOptional object which
is a template class, but when I compile the source I obtain the follow
messages:

> In file included from TExample.cxx:16:
> TExample.h:23: `T' was not declared in this scope
> TExample.h:23: template argument 1 is invalid
> TExample.h:23: ISO C++ forbids declaration of `opt' with no type

Can you help me?
Thanks in advance,
Silvia.

/----- Appendix ------------------------------ /
my header file: TExample.h

#ifndef ROOT_TExample
#define ROOT_TExample
#include <TObject.h>

template <class T> class TOptional : public TObject {
         private:
                UInt_t          lenght;
                T 	        value;
         public:
		TOptional();
		ClassDefT(TOptional,1);
};
ClassDefT2(TOptional,T)
ClassImpT(TOptional,T)

class TChannel : public TObject {
	private:
		char    ch_name[20];
		TOptional<T> *opt;
	public:
		TChannel();
ClassDef(TChannel,1)
};
#endif

My source: TExample.cxx

#include "TExample.h"
TChannel();
/---------------------------------------------/

My compile command:

g++ -O -Wall -fPIC -D_REENTRANT
-I/afs/fusione.it/project/fturoot/ROOT/include/root -c TExample.cxx



--
Silvia Eccher (Iannone) <silvia.eccher@frascati.enea.it>



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:23 MET