In C++17, is there any difference between declaring a global constant like this:
namespace ns
{
static constexpr const auto global_variable = 47;
}
Specifying the const modifier as well, and:
namespace ns
{
static constexpr auto global_variable = 47;
}
Without specifying const? If yes, which are the differences and which version of the declaration is recommended in which scenarios?
inlinerather thanstatic. Or just in an anonymous namespace.static constexpr char* global_variable = "Happy";applies theconstexprto the typechar*, which is as-if it waschar* const. And that's not what you really want. So there you need to dostatic constexpr char const* global_variable = "Happy";.namspace, what are the benefits of making itinlineinstead ofstaticin my example case?