PDA

View Full Version : Template class problem



lni
12th June 2012, 14:24
Hi,

I have 3 DLLs that use the same static variable from a template class instance, such as:

1st DLL:


template <typename T>
class Foo {

public:

static Foo<T>& instance() {
static Foo<T> obj;
return obj;
}

void add( ... ) {
...
}

};



In 2nd dll, I call



Foo<myClass>::instance().add( ... );



In 3nd dll, I also call



Foo<myClass>::instance().add( ... );



In linux things work fine. The Foo<myClass>::instance() contains the 2 items I "add"

However, in Windows, they don't know each other. It appears each has their own "instance". How can I export the instance so all DLLs share it?

Thanks!

amleto
12th June 2012, 18:25
Where is your Qt question?
http://lmgtfy.com/?q=c%2B%2B+dll+template+export
http://lmgtfy.com/?q=c%2B%2B+dll+template+extern