C++ Programming
12-23-2009, 08:00 AM
error C2487: 'CSingleton::ms_pSingleton' : member of dll interface class may not be declared with dll interface
When I try to compile the below code in VS2008 above is the error. I am not sure hw to fix this, as the class is not exported (i am getting this error even when i try to export the member alone).
So please suggest me a better solution.
template
class CSingleton
{
private:
ExportSlotCoreLib static T* ms_pSingleton;
CSingleton(const CSingleton&);
protected:
CSingleton() {
//assert(ms_pSingleton == NULL);
int offset = (char*)(T*)1 - (char*)(CSingleton *)(T*)1;
ms_pSingleton = reinterpret_cast(reinterpret_cast(this) + offset);
}
~CSingleton() {
//assert(ms_pSingleton != NULL);
ms_pSingleton = NULL;
}
public:
static T& GetSingleton() {
return (T&)*ms_pSingleton;
}
static T* GetSingletonPtr() {
return ms_pSingleton;
}
};
Thanks,
Nandu
When I try to compile the below code in VS2008 above is the error. I am not sure hw to fix this, as the class is not exported (i am getting this error even when i try to export the member alone).
So please suggest me a better solution.
template
class CSingleton
{
private:
ExportSlotCoreLib static T* ms_pSingleton;
CSingleton(const CSingleton&);
protected:
CSingleton() {
//assert(ms_pSingleton == NULL);
int offset = (char*)(T*)1 - (char*)(CSingleton *)(T*)1;
ms_pSingleton = reinterpret_cast(reinterpret_cast(this) + offset);
}
~CSingleton() {
//assert(ms_pSingleton != NULL);
ms_pSingleton = NULL;
}
public:
static T& GetSingleton() {
return (T&)*ms_pSingleton;
}
static T* GetSingletonPtr() {
return ms_pSingleton;
}
};
Thanks,
Nandu