Templates in FPL?
Fergus Henderson
fjh@cs.mu.oz.au
Thu, 24 May 2001 02:41:49 +1000
On 23-May-2001, D. Tweed <tweed@cs.bris.ac.uk> wrote:
> On 22 May 2001, Carl R. Witty wrote:
>
> > "D. Tweed" <tweed@cs.bris.ac.uk> writes:
> >
> > > In my experience the C++ idiom `you only pay for what you use' (==>
> > > templates are essentially type-checked macros) and the fact most compilers
> > > are evolved from C compilers makes working with templates a real pain in
> > > practice.
> >
> > I'm not sure what you mean by type-checked here. Templates are not
> > type-checked at definition time, but are type-checked when they are
> > used; the same is true of ordinary macros.
>
> I was thinking in terms of (to take a really simple example)
>
> template<class T>
> void
> initialiseArray(T** arr,const T& elt,int bnd)
...
> If I try and use intialiseArray(<obj of type foo>,<obj of type bar>), with
> the template function I get the error when passing in the parameters;
In other words, *calls to* template functions are type-checked at compile time.
However, *definitions of* template functions are only type-checked when they
are instantiated.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.