
static template class member variable in DLL
Yep, that's what I'd expect.
I think what happens is the compiler sees the requirement for a
static member in the dll, and also in the client - but they're two
different variables (in two different data segments).
Maybe you want to look at TLS (thread local storage). There's also
loads of stuff in 'afxtls_.h' if you're feeling brave.
Regards Alec.
Quote:
> I'm using a simple template class in a DLL which
> contains a static member variable.
> However when I examine this variable in the
> context of the client using the DLL, its different
> than when I examine it in the context of the DLL!
> Sample:
> mydll.h:
> template<class T>
> class MyTemplate
> {
> public:
> MyTemplate();
> T Val() {
> return *NIL;
> }
> public:
> static T* NIL;
> };
> template<class T>
> inline MyTemplate<T>::MyTemplate()
> {
> if( 0 == NIL ) {
> NIL= new T;
> *NIL= 0;
> }
> }
> // The one and only
> template<class T> T* MyTemplate<T>::NIL = 0;
> class AFX_EXT_CLASS MyClass : public CObject
> {
> public:
> MyClass();
> char Val() {
> return mString.Val();
> }
> public:
> MyTemplate<char> mTemp;
> };
> mydll.cpp:
> #include "mydll.h"
> MyClass::MyClass()
> {
> }
> =========================
> Here is some client code
> fun()
> {
> MyClass xyz; // Allocates a new NIL ptr
> MyTemplate<char> test; // Also allocates a new NIL ptr?
> xyz.Val();
> xyz.mTemp.Val();
> test.Val();
> }
> Whats going on?
> Thanks Kevin