
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