Is there any advantage to using private (probably also static) functions in a class for utility functions used in my class that do not need access to an instance’s data over using global static functions in my .cpp file that implements the class?
The first sounds cleaner to me, but the second really makes more sense as these functions do not need to even be mentioned in the .h file.
Is there any advantage to using private (probably also static ) functions in a
Share
I would not put private static functions to the header file if they are not needed. They would just pollute the header file and add more work.
But private static functions may be needed when you have a template method/function in a class and want to use that helper function in it.
Another reason for using private static functions instead of global static functions is that they can access private class members (variables, functions).