C++, static vs. namespace vs. singleton

后端 未结 6 1589
孤城傲影
孤城傲影 2020-12-01 07:34

I already read a lot of posts and articles all over the net, but I couldn\'t find a definite answer about this.

I have some functions with similar purposes that I wa

6条回答
  •  伪装坚强ぢ
    2020-12-01 08:05

    Don't make it a singleton

    For public helper functions that don't directly depend on these variables, make them non-member functions. There's nothing gained by putting them in a class.

    For the rest, put it in a class as normal non-static members. If you need a single globally accessible instance of the class, then create one (but don't make it a singleton, just a global).

    Otherwise, instantiate it when needed.

提交回复
热议问题