Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. error C2487

error C2487

Scheduled Pinned Locked Moved C / C++ / MFC
help
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nandu_77b
    wrote on last edited by
    #1

    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

    K 1 Reply Last reply
    0
    • N Nandu_77b

      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

      K Offline
      K Offline
      KingsGambit
      wrote on last edited by
      #2

      Can you remove ExportSlotCoreLib from pSingleton declaration and try?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups