In order to support generic programming, C++ has templates. But since templates are purely a compile-time construct (much like anything else in C++), it looks like there's not much point in trying to use them in a dll.
Let's say we want to create a math library that comprises a number of templated functions. As long as this library is statically linked with an application, we're OK. You can argue
that we can statically link a dll
to an application too (provided you have access to the source/or object files) but most of the time we just want to use the dll (by loading it via LoadLibrary
and calling a particular function with
GetProcAddress
)
So, does the above mean that we can't really use templates in a dll (if they're to be used externally)? And what are (if any) alternatives, apart from static libraries?