C++ singleton vs completely static object

前端 未结 5 435
陌清茗
陌清茗 2020-12-13 00:12

Let say we need to have just one instance of some class in our project. There are couple ways of doing it.

I want to compare. Please can you review my understanding.

5条回答
  •  时光说笑
    2020-12-13 00:53

    You could also use the Borg pattern, which is a little more complicated in C++ unless you have access to a shared pointer class. The idea is that any number of Borg classes can be instantiated, but their state is shared across all instances.

提交回复
热议问题