Consider the following code:

Code:
template<class TYPE>
void MultiplyByTwo(TYPE data)
{
    cout <<"Double =  " << data * 2 << endl;
}
If I declared that code in a header file I'd be able to call it with an int, float, double or whatever. But where does the actual code get instantiated? Is it effectively inlined?

What I'm wondering is if there'd ever be any scenario for putting such code in a DLL - e.g.

Code:
#ifdef BUILDING_MY_DLL
    #define MY_DLL_API __declspec(dllexport)
#else
    #define MY_DLL_API __declspec(dllimport)
#endif 


template<class TYPE>
MY_DLL_API void MultiplyByTwo(TYPE data)
{
    cout <<"Double =  " << data * 2 << endl;
}
I just tried it and was slightly surprised to find it wouldn't compile. It compiles fine when actually building the DLL but when I try to build something else which uses that DLL I get compiler error C2491 (definition of dllimport function not allowed).

I guess that kinda makes sense if template functions are effectively inlined... or is there some other explanation