static template class member variable in DLL 
Author Message
 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



Fri, 04 Jun 1999 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Static member variables of template class

2. static members in template class across DLL's

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. template classes with static members

10. static member variable inside class

11. LNK1169 & static const class member variables

12. write to static class member variable...

 

 
Powered by phpBB® Forum Software