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. template classes & dlls

template classes & dlls

Scheduled Pinned Locked Moved C / C++ / MFC
1 Posts 1 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.
  • T Offline
    T Offline
    Themis
    wrote on last edited by
    #1

    Hi there. I have two projects in a solution (VS8.0) and the first has a dependency on the other. Both projects produce dlls. Now I want to define a simple singleton and use it from both dlls. So the code is easy: class _MyProject_Export BuilderFactory : public util::DllFactory { public: static BuilderFactory& Instance(void) { static BuilderFactory singleton; return singleton; } }; Ok we have a BuilderFactory class that it inherits from another class and just define a static member Instance to get reference to my singleton. Of course having such a code you are going to templatize the code in the following fashion: template class Singleton { public: typedef T SingletonType; static T& Instance(void) { static T singleton; return singleton; } private: Singleton(void) {} Singleton(const Singleton&); Singleton& operator =(const Singleton&); virtual ~Singleton(void) {} }; typedef Singleton< util::DllFactory > BuilderFactory; Both example compile successfully, however the latter doesn't work! Just can't understand why. I came to believe that in the latter case two different instances exist in my program. As I'm registering builders in the factory from on dll and the second doesnt have any. I suspect that something has to do with exporting of symbols as I don't export anything in the latter case, but what am I supposed to export, the typedef? Any ideas?

    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