R
Russ Ford
Hi all,
34.13-14 of the FAQ shows that to instantiate a template, you can make
another source file that includes the .cc file where the definition of the
functions is contained:
---------------------------------
foo.h:
template <class T> void somefn();
foo.cc
template <class T> void somefn() {}
foo-impl.cc
#include "foo.h"
#include "foo.cc"
template void somefn<int> ();
---------------------------------
My question: is it ok to just include the explicit instantiation at the end
of foo.cc (as a macro)? It compiles OK, but I just want to make sure that
I'm not creating problems long term. My idea is this:
-----------------------------------
foo.h (same)
foo.cc:
template <class T> void somefn() {}
#define TEMPL_IMPL(T) template void somefn<T> ();
TEMPL_IMPL(int);
34.13-14 of the FAQ shows that to instantiate a template, you can make
another source file that includes the .cc file where the definition of the
functions is contained:
---------------------------------
foo.h:
template <class T> void somefn();
foo.cc
template <class T> void somefn() {}
foo-impl.cc
#include "foo.h"
#include "foo.cc"
template void somefn<int> ();
---------------------------------
My question: is it ok to just include the explicit instantiation at the end
of foo.cc (as a macro)? It compiles OK, but I just want to make sure that
I'm not creating problems long term. My idea is this:
-----------------------------------
foo.h (same)
foo.cc:
template <class T> void somefn() {}
#define TEMPL_IMPL(T) template void somefn<T> ();
TEMPL_IMPL(int);