I have a template class that has become overly complex and unwieldy. I
would like to break it up into an interface (*.h) and one or more
implementation files (*.cpp). The compiler will not let me do that. Is
there a recommended work-around to break up a large template class into
multiple files?
The theoretically correct idea is to use the 'export' keyword -- but
your compiler probably doesn't support it (only one, Comeau C++,
does).
Lacking that, you have a few choices. If you _just_ want separate
files, you can move pieces of code into separate files, and have a
header that contains the template definition, and includes the
definitions of individual functions as needed. This still works
pretty much like one huge header though -- in particular, your source
files still depend on all the pseudo-headers, and any change in any
of them forces recompilation of the source files.
You can get away from that under a _few_ circumstances. For example,
if your templates are primarily collections of T, you can (at least
sometimes) get away with writing some base code that works with
pointers to void, and then write a small template that takes care of
casting from T * to void * and back as needed. At one time this was
quite common, but now that most people primarily just use the
containers in the standard library, it's not useful very often.