RE: [GD-Windows] dll export and template
Brought to you by:
vexxed72
From: Nicolas R. <nic...@fr...> - 2002-08-05 12:23:54
|
Yes... template and DLLs are badly working together... Under VC7 you can at least declare the template exported... template<class T> class __declspec(dllexport) mytemplate { }; will correctly export the template. Note however that the export is only done on used template definitions... Export/import scheme defined automatically by VC++ is not sufficient... Let say you have a header containing: template<class T> class MYDLL_API mytemplate { }; A DLL is compiling with MYDLL_API to __declspec(dllexport). If it use it with T = MyDLLClass1 and MyDLLClass2, only mytemplate<DLLClass1> and mytemplate<DLLClass2> will be exported. If an external program is including the header (with MYDLL_API to __declspec(dllimport)) it won't be able to use the template for a "ExeClass" since it won't be exported by any DLL... Still havent find any way to correctly export the template itself (but using the #pragma warning(disable:xxxx) before using a non exported template). Nicolas. -----Original Message----- From: gam...@li... [mailto:gam...@li...]On Behalf Of jason zhang Sent: lundi 5 août 2002 09:48 To: gam...@li... Subject: [GD-Windows] dll export and template There was a compile warning when I use template in my export class of DLL. And the compiler will give an error if I put __declspec(dllexport) keyword before the my template definition. My question is whether it is safe if I just disable the warning. The warning is: "The specified base class was not declared with the __declspec(dllexport) keyword.A base class or structure must be declared with the __declspec(dllexport) keyword if a function in a derived class is to be exported. " . The code is: template<class T> mytemplate { T t; public: void SetData( T &_t ){ t = _t; } }; class MYDLL_API MyClass { mytemplate<int> data; public: .... }; N±ùµéX²²u¼)çYé¢g¢½é¶ÚþØHzGû©uëËÂ)£ j) ²Ñç¾X¶ÌÚ²X¶Ëº·~zwÛ³ÿ˲qç®zßËþX¶)£øç¾X¶ÌÚ° +²§ÿ¢êyúé·ùVr{÷®é®ét |