'Helper' functions in C++

前端 未结 7 788
轻奢々
轻奢々 2021-02-01 03:20

While refactoring some old code I have stripped out a number of public methods that should actually of been statics as they a) don\'t operate on any member data or call any othe

7条回答
  •  死守一世寂寞
    2021-02-01 04:10

    The main advantage to using a namespace is that you can reopen it and add more stuff later, you can't do that with a class. This makes this approach better for loosely coupled helpers (for example you could have a Helpers namespace for your entire library, much like all of STL is in ::std)

    The main advantage of a class is that you can nest it inside the class using it, you can't nest a namespace in a class. This makes this approach better for tightly coupled helpers.

    You won't have any extra overhead having them in a class vs a namespace.

提交回复
热议问题