'Helper' functions in C++

前端 未结 7 786
轻奢々
轻奢々 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 03:47

    Overhead is not an issue, namespaces have some advantages though

    • You can reopen a namespace in another header, grouping things more logically while keeping compile dependencies low
    • You can use namespace aliasing to your advantage (debug/release, platform specific helpers, ....)

      e.g. I've done stuff like

      namespace LittleEndianHelper {
         void Function();
      }
      namespace BigEndianHelper {
         void Function();
      }
      
      #if powerpc
         namespace Helper = BigEndianHelper;
      #elif intel
         namespace Helper = LittleEndianHelper;
      #endif
      

提交回复
热议问题