How to implement a Singleton in an application with DLL

前端 未结 3 1444
闹比i
闹比i 2021-01-22 05:14

I have an application (in MS Visual Studio) that contains 3 projects:

  • main (the one that contains the main function)
3条回答
  •  醉话见心
    2021-01-22 06:14

    I believe that defining and accessing singleton instance this way might solve your problem:

    Config& getInstance()
    {
      static Config config;
      return config;
    }
    

    This way you also don't need to have (and call) the Initialize method, you can use constructor for initializing, that will be called automatically when you call getInstance for the first time.

提交回复
热议问题