Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 3rd, 2007, 5:03 AM   #1
rwm
Professional Programmer
 
Join Date: Jan 2007
Location: Cape Town
Posts: 291
Rep Power: 2 rwm is on a distinguished road
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
rwm is offline   Reply With Quote
Old Jan 3rd, 2007, 6:01 AM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,254
Rep Power: 5 grumpy will become famous soon enough
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).
grumpy is offline   Reply With Quote
Old Jan 8th, 2007, 2:51 AM   #3
rwm
Professional Programmer
 
Join Date: Jan 2007
Location: Cape Town
Posts: 291
Rep Power: 2 rwm is on a distinguished road
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!
rwm is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:21 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC