|
From: <h.r...@gm...> - 2002-03-03 01:24:07
|
> > -----Original Message-----
> > Subject: [Dev-C++] template and prototype
> >
> >
> > Hello,
> >
> > Is it forbidden to have a prototype of a template in a header file ?
> > For example:
> >
> > a.h
> > template <class T> T sqr(T x);
> >
> > a.cpp
> > template <class T> T sqr(T x) { return x * x; }
> >
> > this doesnt link.
> > If I put the definition
> > template <class T> T sqr(T x) { return x * x; }
> > in the header, it works.
>
> If you want to place the definition in one file and use declarations to
> the rest, you must place the keyword export in the template definition
> in the style:
>
> export template <class T>
> T sqr(T x) { return x*x; }
>
>
> Then you can use the declaration in the way you used it to access the
> template from other translation units. The export is necessary to make
> it possible someone to make a compiler that knows what is going on. :)
> If you do not like export you must provide the template definition in
> every unit you use it (templates have by default local scope in contrast
> to ordinary functions).
>
> Ioannis
Hi Ioannis,
many thanks for the quick answer.
I followed your tip but the linker means:
3 hr_math.cpp
warning: keyword 'export' not implemented and will be ignored
Horst
PS: sorry Ioannis for the PM
--
--------------------------
Horst Rößner
Postf. 1802
52205 Stolberg
02402 / 6178
0171 6455636
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
|