I want to be able to provide a default name to a class so that I can always have a reasonable name to use when logging errors. I don't need (or want) this name to be a part of the class itself. This default name will never change and so is a good candidate for being const
or even constexpr
but you can't do constexpr QString
or constexpr std::string
for whatever reason.
In my cpp file, is it better to do
namespace {
const QString NAME("Some Name");
}
or
namespace {
static const QString NAME("Some Name");
}
I know that both versions will result in NAME
having internal linkage, but what is best practice? I've seen several discussions on moving global variables to an anonymous namespace but none of them mention using static
inside the namespace.
References: