template classes & dlls

Hi there.

I have two projects in a solution (VS8.0) and the first has a dependency on the other. Both projects produce dlls. Now I want to define a simple singleton and use it from both dlls. So the code is easy:

[code]
class _MyProject_Export BuilderFactory :
public util::DllFactory
{
public:
static BuilderFactory& Instance(void)
{
static BuilderFactory singleton;
return singleton;
}
};
[/code]

Ok we have a BuilderFactory class that it inherits from another class and just define a static member Instance to get reference to my singleton. Of course having such a code you are going to templatize the code in the following fashion:

[code]
template
class Singleton
{
public:
typedef T SingletonType;

static T& Instance(void)
{
static T singleton;
return singleton;
}

private:
Singleton(void) {}
Singleton(const Singleton&);
Singleton& operator =(const Singleton&);
virtual ~Singleton(void) {}
};

typedef Singleton<
util::DllFactory
> BuilderFactory;
[/code]

Both example compile successfully, however the latter doesn't work! Just can't understand why.

I came to believe that in the latter case two different instances exist in my program. As I'm registering builders in the factory from on dll and the second doesnt have any. I suspect that something has to do with exporting of symbols as I don't export anything in the latter case, but what am I supposed to export, the typedef?

Any ideas?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories