I am trying to create a Service Locator component and below is the implementation.
#ifndef __SERVICE_LOCATOR_H__
#define __SERVICE_LOCATOR_H__
#include <map>
using namespace std;
class ServiceLocator
{
static map<string, void*> m_mapRegisteredTypes;
public:
template<class T> static void Register(const T*);
template<class T> static T* Resolve();
virtual ~ServiceLocator() = 0;
};
ServiceLocator::~ServiceLocator(){}
map<string, void*> ServiceLocator::m_mapRegisteredTypes;
template<class T>
void ServiceLocator::Register(const T* object)
{
ServiceLocator::m_mapRegisteredTypes[typeid(T).name()] = (void *)object;
}
template<class T>
T* ServiceLocator::Resolve()
{
return (T*)ServiceLocator::m_mapRegisteredTypes[typeid(T).name()];
}
#endif /*__SERVICE_LOCATOR_H__*/
When I am trying to use it in two different DLLs, they are making thier own copy of ServiceLocator class.
How can share static map<string, void*> m_mapRegisteredTypes
across DLLs.