Archived

This topic is now archived and is closed to further replies.

learner

Template class in a dll

Recommended Posts

I''m trying to create template classes in a dll and having a little bit of problem. The problem with dll is that you could only export classes through interface. When using interface, you will need a function to create and free the interface. The problem is, how to let the function know which type of template to create?
  
template class<Type> class Test
{
public:
Type Get();
}

//Here is the problem how would I declare the create function?

//What is the parameter to use so that the clien could specify

//the Type?

//void CreateTest();

  

Share this post


Link to post
Share on other sites
im not sure what ur trying to do. But if you''re trying this:>

int main(int, char**)
{
LoadLibrary("mydll.dll");
MyClass myObject;
return 0;
}

this isn''t possible, as template classes is strictly compiler blaha(can''t come up with the word for it). As a dll is compiled code it can''t be done.(i think) :=)

I could be wrong however... eh might wanna try searching google.com for dll "template classes" or whatever...

happy hunting

In the next 80 years 6 billion people will die...

Share this post


Link to post
Share on other sites
you can freely use template classes in a dll, but I fail to understand what you are trying to do ... a dll cannot (and does not need to) export a template ... because a template, by definitions, required complete definition in every compilation which uses it ... so basically, the templates use in each dll and application will be compiler into that dll or application ... there is no importing or exporting, because there is no external linking as far as the compiler rules are concerned. In the real world (some) linkers do remove template duplicates in libraries, when they create an app from them ... but this is only possible with static libraries .. not with multiple apps or multiple dlls. As far as I know.

Share this post


Link to post
Share on other sites
Templates get compiled when you use them. Because all the template code has to be in the class definition (usually in a header file), and you have to #include that class definition in order to use the class, you don''t need to use the DLL for it at all; it''ll just get compiled into your app.

You can''t export templates themselves. However, it is possible to export certain *instantiated* templates - that is, rather than exporting mytemplate, you can export mytemplate or mytemplate.

Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.

Share this post


Link to post
Share on other sites