Multiple-File Template Implementation
Posted
by
Maxpm
on Stack Overflow
See other posts from Stack Overflow
or by Maxpm
Published on 2010-12-21T05:07:26Z
Indexed on
2010/12/21
5:21 UTC
Read the original article
Hit count: 230
With normal functions, the declaration and definition are often separated across multiple files like so:
// Foo.h
namespace Foo
{
void Bar();
}
.
// Foo.cpp
#include "Foo.h"
void Foo::Bar()
{
cout << "Inside function." << endl;
}
It is my understanding that this cannot be done with templates. The declaration and definition must not be separate because the appropriate form of the template is created "on-demand" when needed.
So, how and where are templates typically defined in a multiple-file project like this? My intuition is that it would be in Foo.cpp
because that's where the "meat" of functions normally is, but on the other hand it's the header file that's going to be included.
© Stack Overflow or respective owner