C++: How to design a utility class?

Martijn Courteaux picture Martijn Courteaux · Jun 18, 2010 · Viewed 16.8k times · Source

But I don't know if I should go for static methods, just a header, a class, or something else?

What would be best practice? But, I don't want to have an instance of a utility class.

I want to add functions like:

Uint32 MapRGB (int r, int g, int b);
const char* CopyString(const char* char);
// etc. You know: utility methods...

Answer

James McNellis picture James McNellis · Jun 18, 2010

Don't put them in a class; just make them non-member functions at namespace scope.

There's no rule that says every function has to be a member function of some class.