Hello,
I would like to have a Singleton class that ensures to have only one instance wherever the code flow is in a DLL or in the main program.
My Singleton class is like this:
My problem is that I have two different instances of a Singleton. One in my DLL and one in my main program.
In the main program :
It prints two different addresses.
Is it possible to have a real Singleton?
I'm using VC++ 6.0.
--
Globos
I would like to have a Singleton class that ensures to have only one instance wherever the code flow is in a DLL or in the main program.
My Singleton class is like this:
Code:
template<class G>
class Singleton
{
public:
// Unique instance of type G.
static G* instance ()
{
static G* _instance = Void;
if (_instance == Void)
_instance = new G;
return _instance;
}
};
My problem is that I have two different instances of a Singleton. One in my DLL and one in my main program.
In the main program :
Code:
int main ()
{
Object* object = Singleton<Object>::instance ();
cout << "address in main : " << object << endl;
// Load the function test_in_dll() from the DLL and access the singleton inside...
// Call the function :
test_in_dll ();
return 0;
}
void test_in_dll ()
{
Object* object = Singleton<Object>::instance ();
cout << "address in dll : " << object << endl;
}
It prints two different addresses.
Is it possible to have a real Singleton?
I'm using VC++ 6.0.
--
Globos