I have a class which needs to be a singleton. It implemented using a static member pointer:
class MySinglton
{
public:
static MySinglton& instance() { ... }
private:
static MySinglton* m_inst;
};
This class is compiled into a .lib which is used in multiple dlls in the same application. The problem is that each dll sees a different m_inst. since it is compiled and linked separatly.
What is simple way to solve this problem?
Separating the .lib to its own dll is not an option. it must be a .lib.
A solution could be transferring the instantiation to the application, and the DLLs will get reference to it during initialization.
It may not be as elegant as you’d like, but it would do it.
Need to know what’s the REAL problem behind your question.
The answer may not be in the form you expect it. 😉