This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]