OK so what about using templates and overloading in DLL, I want my dll to store  functions for all the basic types, this function is a template . How can i do this ??
Posted on 2005-06-12 11:19:53 by AceEmbler
I guess the answer is "you can't", for the same reasons that require templates to be in header files...
Posted on 2005-06-12 11:23:41 by f0dder

OK so what about using templates and overloading in DLL, I want my dll to store  functions for all the basic types, this function is a template . How can i do this ??


There is no problem using overloading in DLLs.

For templates, there are 3 common ways of organization: the inclusion model, the separation model, and explicit instantiation. The inclusion model means you put your template's body in the header. The separation model means using the 'export' keyword, which is currently fully supported only by Comeau, which AFAIK doesn't yet support DLLs. Explicit instantiation can be used to do what you want:

Header file:


template<typename T> void foo();


DLL source file:


template<typename T> void foo()
{
    ...
}

template void foo<int>();
template void foo<double>();


The client can only use the instantiations in the DLL (int/double template arguments in this case).
Posted on 2005-06-12 12:12:08 by death
Oh - nice to learn something new ^_^
Posted on 2005-06-12 12:18:31 by f0dder
That's what i was looking for thx death.
Posted on 2005-06-12 12:28:19 by AceEmbler