Advantages of classes with only static methods in C++

If you want to create a collection of utility functions without clobbering the global namespace, you should just create regular functions in their own namespace:

namespace utility {
    int helper1();
    void helper2();
};

You probably don’t want to make them static functions either.
Within the context of a non-member function (as opposed to a member function), the static keyword in C and C++ simply limits the scope of the function to the current source file (that is, it sort of makes the function private to the current file). It’s usually only used to implement internal helper functions used by library code written in C, so that the resulting helper functions don’t have symbols that are exposed to other programs. This is important for preventing clashes between names, since C doesn’t have namespaces.

Leave a Comment