为什么GitHub C ++核心指南说全局对象比单例更好?

Why GitHub C++ Core Guideline says that global object better than singleton?

GITHUB C++核心指南说:

A global object is often better than a singleton.

我总是想相反。从那时起,C++中发生了什么变化?或者可能只是另一个打字错误?


这是避免同一指南集合中出现单例的原因:

I.3: Avoid singletons

Reason

Singletons are basically complicated global objects in disguise.

Example

1
2
3
4
class Singleton {
    // ... lots of stuff to ensure that only one Singleton object is created,
    // that it is initialized properly, etc.
};

There are many variants of the singleton idea. That's part of the problem.

我对作者意图的分析:

越简单越好。如果将全局对象隐藏在单例中并不能解决全局对象的问题(正如上面的指导方针所暗示的那样),那么就没有必要使用伪装使代码复杂化。