static members in template class across DLL's 
Author Message
 static members in template class across DLL's

I have written a template which declares a static variable
for each instantiation of the template. Something like
this: (See "Pattern Hatching" by John Vlissides Page 143
to see the real template and instantiations)

template <class T> class TEvent
{
private:
    static int x;

Quote:
}

I then instantiate the template and define the static
variable for this class in a CPP file in a DLL. Something
like this:
(in header)
class MyEvent : public TEvent<MyEvent>
{
Quote:
};

(in CPP)
int MyEvent::x;

I can build this DLL with no link errors and use MyEvent
within this DLL but can not use the class from any other
DLL's. I get a link error saying MyEvent::x is not
defined. (I am exporting the MyEvent class only as a
template class do I have this problem)

Can you really not have static members in templates that
are used across DLL's? Doesn't the STL do this?

Thanks
Stephen



Tue, 16 Nov 2004 06:55:07 GMT  
 static members in template class across DLL's
Hi,

I recommend the KB article Q168958 on HOWTO: Exporting STL Components
Inside & Outside of a Class. You can access it in MSDN or MSDN online at:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q168958

Regards,
HuangTM
This posting is provided "AS IS" with no warranties, and confers no rights.



Tue, 16 Nov 2004 09:34:10 GMT  
 static members in template class across DLL's

Quote:

> Hi,

> I recommend the KB article Q168958 on HOWTO: Exporting STL Components
> Inside & Outside of a Class. You can access it in MSDN or MSDN online at:
> http://support.microsoft.com/default.aspx?scid=kb;EN-US;q168958

Unfortunately, some of what it says is wrong. For example, it says that
you can't export deque instances because you can't put the
__declspec(__export) modifier on deque::iterator. While the latter is
true, the former doesn't follow. The member functions of deque::iterator
are all inline, so they'll be generated wherever they're used. You don't
need to export them.

--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)



Wed, 17 Nov 2004 21:17:08 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. static template class member variable in DLL

2. exporting template class' member functions from dll

3. template classes with static members

4. static data member of template class

5. Initialization of static data member of template class

6. template classes with static members

7. Static member definition of template class fails

8. Static member definition of template class fails

9. Static member variables of template class

10. template classes with static members

11. Unresolved static template data member exported from DLL

12. can't invoke template class member function

 

 
Powered by phpBB® Forum Software