Mail Archives: djgpp/1995/10/28/14:26:29
a920101 AT zipi DOT fi DOT upm DOT es writes:
> How do I use them in GCC??? I've searched in the docs and so, but can't find
> anything. Help?
The information you need _is_ in the info files; it's just not
straightforward or easy to find. (I plagued this group a while ago
with questions about templates myself.)
What you basically have to do is 1. define the template class, 2.
instantiate it in a certain module for your particular application,
and 3. include that module in with the rest of your modules for
linkage.
Search around in the gcc documentation for templates; you should find
the information you need. Basically, what you do is make whatever
typedefs you feel are appropriate, and then instantiate the template
with a syntax which looks like a prototype definition (using
templates) for everything you need.
First you do something like
template class LIST<Data>;
that instantiates the class itself and its member functions. For out-
of-line member functions, say, an operator << function for writing a
LIST<Data> to an iostream, you use a template instantiation something
like the following:
template ostream &operator <<(ostream &o, const LIST<Data> list);
This should do the trick. I use this on a regular basis and have
never seen any troubles. I've found that with gcc if you try the
other route, which is to _use_ the template classes in this manner
(even if you do it in a way which is never used), the instantiations
seem to be optimized out. The above description is the way to go.
Erik Max Francis, &tSftDotIotE || uuwest!alcyone!max, max AT alcyone DOT darkside DOT com
San Jose, California, U.S.A. || 37 20 07 N 121 53 38 W || the 4th R is respect
H.3`S,3,P,3$S,#$Q,C`Q,3,P,3$S,#$Q,3`Q,3,P,C$Q,#(Q.#`-"C`- || 1love || folasade
_Omnia quia sunt, lumina sunt._ || GIGO Omega Psi || http://www.spies.com/max/
"Hands that once picked cotton can now pick Presidents." -- Jesse Jackson
- Raw text -