c++ - Design for generic utility code with no 'member' data -
i creating generic utility functions no persistent class type data used in project.
so thinking have following options:
- create global functions inside namespace. 
- create global functions (in global namespace). 
- create class static functions. 
i realise b) not particularly practice. when choose a) or when c)? or indeed other options haven't thought of?
i choose options below:
- c - if functions can relate each other closely
- a - if functions can relate each other moderately
- b - if functions not related each other (keep @ least in same folder)
below examples can template well.
 example c:
struct sort {  // sorting data structure operations   static void quick (..);   static void bubble (..);   static void merge (..); }; example a:
namespace util {  // data structures operations   static void sort (..);   static void binary_tree (..);   static void hash_map (..); } example b:
// operations void swap (..); void erase (..); void destroy (..); 
Comments
Post a Comment