uuu777
uuu777

Reputation: 901

singletons and google coding-style

Google c++ coding-style does not allow non-trivial static objects (and for a reason) and hence no singletons. At the same time singletons do represent reality of application logic.

So what is the correct way to implement singleton functionality google-style:
(a) have static pointers and initialize them on startup as a separate step (e.g. by linked list of initializer/maker classes)
(b) have context holding references to all singleton-like object and pass it with every method (c) have context to be member of every class
(d) something else?

Upvotes: 3

Views: 529

Answers (1)

VonC
VonC

Reputation: 1323045

The "Google C++ Style Guide" does mention "Types representing singleton objects (Registerer)"

You can see an implementation of said registerer in ronaflx/cpp-utility with "util/registerer.h" for function pointers (illustrated here), and util/singleton.h for classic singleton.

The OP points to their own project alex4747-pub/proper_singleton.

Upvotes: 1

Related Questions