Is it still worth using static functions in C++ as a helpers?
Example:
in file.cpp
static void helperFunc() { do something }
// class implementation
// ...
// some public method, not static
void myClass::doSomething() { helperFunc(); }
That way I do not have to declare private method in class’s declaration.
Or maybe it is better to use unnamed namespaces and write (in the same file as above)?
namespace {
void helperFunc() { }
}
What is better?
Neither of your two examples is better than the other. It’s a matter of style. The
statickeyword is more expressive. It outright spells out “do not export this name”. Using an anonymous namespace is not that expressive. The fact that the name won’t get exported is a side-effect, not a primary function.