1) utility class, use only static methods, block copying and creation
class myUtils
{
public:
static void utilFunc();
static void utilGreatFunc();
private:
utils() { } // block creation
utils(const utils &) { }
~utils() { }
}
2) use namespace
namespace myUtils
{
void utilFunc();
void utilGreatFunc();
}
what is the best way of doing this? I suppose the namespace way, it is much clearer to me and simpler to write. Or maybe there is some other and better design?
You never use a “utility class with static methods” in C++. That’s a Java-ism. Instead, use your second solution and put the functions in a
namespace.