error C2487
-
error C2487: 'CSingleton<T>::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 <typename T> 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>*)(T*)1; ms_pSingleton = reinterpret_cast<T*>(reinterpret_cast<char*>(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
-
error C2487: 'CSingleton<T>::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 <typename T> 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>*)(T*)1; ms_pSingleton = reinterpret_cast<T*>(reinterpret_cast<char*>(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
Can you remove ExportSlotCoreLib from pSingleton declaration and try?