Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 276
uuu777 Avatar asked Aug 04 '26 01:08

uuu777


1 Answers

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.

like image 190
VonC Avatar answered Aug 06 '26 22:08

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!