![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
Join Date: Jan 2007
Location: Cape Town
Posts: 291
Rep Power: 2
![]() |
exporting template classes to DLL
hi,
ive got a problem exporting template classes to dll... for example, this works: #define DllExport __declspec(dllexport)
class DllExport myClass {
public:
...
};but this doesnt work #define DllExport __declspec(dllexport)
template<typename T>
class DllExport myClass {
public:
...
};i tried doing this: typename myClass<int> myClassInt; DllExport myClassInt; doesnt work are there any workarounds? can someone help me out here? i hope so! thx ![]() |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,254
Rep Power: 5
![]() |
The solution is compiler dependent (meaning you need to read your compiler documentation to be sure of the precise techiques) but is usually a variation of something like this ...... You would have to add the __declspec() prefix to the declaration of each member function in the class. And specialise the template within the DLL so it supplies and exports the classes (eg myclass<int>, myclass<double>, etc) that you intend to allow applications to employ.
In the end, it is usually easier to use the templates directly within applications that need them, than it is to attempt to supply all required specialisations in a DLL. Particularly as the DLL will only be usable from applications built with the same compiler as the DLL (thanks to the wonders of name mangling, and the fact that all compilers are strongly encouraged by the C++ standard to mangle function names in different ways). |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Jan 2007
Location: Cape Town
Posts: 291
Rep Power: 2
![]() |
hey thx for the reply! sorry im replying late, been hecticly busy here!
umm, i dont quite understand what you getting at - can u give an example??? im using visual studio compiler hope you can help! thx! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| friends, templates, and other s**t | bl00dninja | C++ | 4 | Oct 14th, 2006 2:15 AM |
| Could some please explain classes to me... | TCStyle | C++ | 10 | Feb 20th, 2006 4:51 PM |
| Help: Template Class' copy constructor | MicahCarrick | C++ | 2 | Jan 23rd, 2006 6:33 AM |
| Function Template Question | aznluvsmc | C++ | 6 | Oct 8th, 2005 12:37 AM |
| Template + operator problem | Polyphemus_ | C++ | 3 | Sep 30th, 2005 7:43 PM |