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:

  1. create global functions inside namespace.

  2. create global functions (in global namespace).

  3. 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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -