This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Template Question
- From: "Eric Lemings" <eric at lemings dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Thu, 27 Mar 2003 07:13:41 -0700
- Subject: Template Question
Hi,
Using g++, can templates not be compiled separately from files that use them
and linked like normal object files? Or do the template source files have
to be included like header files in the source files that use them? For
example,
::::::::::::::
Test01.h
::::::::::::::
template <class T>
void foo (const T& t);
::::::::::::::
Test01.cpp
::::::::::::::
#include "Test01.h"
template <class T>
void foo (const T& t) {
// do something with t
}
::::::::::::::
Main.cpp
::::::::::::::
#include "Test01.h"
int main (void) {
foo<long> (42);
return (0);
}
Can g++ compile and link these files just as if foo() were a plain ol'
function? The GCC documentation on this topic appears to be obsolete.
Thanks,
Eric.