Sign in to follow this  
Woltan

Wrapper organization

Recommended Posts

Hey ho folks, I am programming now a while and I build myself some nice classes, like a linked list, a tree or some other usefull stuff. So I though it'd be kind of cool to have all this in a dll. Unfortunatly it is not possible to put template based classes in a dll. So does anyone has a suggestion on how I could work around that problem? Maybe there is an alternative to a dll? I hope someone can help me on this vague question. thanks in advance cherio Woltan

Share this post


Link to post
Share on other sites
AFAIK, there is currently no compiler that lets you even put the declaration and implementation of your templated classes in different files, so I don't think it's possible. Sorry.

Share this post


Link to post
Share on other sites
okey. Can someone tell me if the following statement is true or false?
"Since it is not possible to put a template based class in a dll, no other classes which have elements of the template based class can be put in a dll."
Sorry for my english but I hope the statement is understandable.
thanks for a reply
cherio Woltan

Share this post


Link to post
Share on other sites
Quote:
Original post by Valderman
AFAIK, there is currently no compiler that lets you even put the declaration and implementation of your templated classes in different files, so I don't think it's possible. Sorry.


Well, technically, there's at least one, Comeau, which supports the export keyword and allows you to separate interface from implementation in templates. Borland C++ BuilderX (don't know) may support them now as well. In fact, it can technically be done in a hackish way with VC++ (and probably GCC) in a hackish way, which I posted a little bit about a good while ago here. (You could also find it on [google].)

And I'm not sure, but it is probably legal to export predefined specializations for templates (e.g. templ<int> var) to .DLLs, because the code is generated at compile-time. But that's just a guess, and I haven't tried it before.

Share this post


Link to post
Share on other sites
I'm pretty certain C++ BuilderX doesn't support it. And yes, you can use a DLL to export explicit template instantiations.

You can put a class that has member variables that are of a template type in a DLL. For example, you can put a class that has a std::string member in a DLL. However, templated member functions are still not happy, and exporting a class with a member variable of a templatee type may require you to export the template instantiation from a DLL.

In general, DLL interfaces are a really bad place to be exposing implementation details. When exporting a class from a DLL, it's good practice to instead publish an abstract base class from which a DLL will give a factory function that returns an instance of the class.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this