You can do similar things, but they will have different semantics.
In a class, a static variable is a declaration, not a definition; it still requires a definition outside the class; Declaring a variable in the namespace is a definition unless you check how externand provide an initializer.
In your case, this does not really matter, since the variables consthave an internal binding by default, so you can easily have several definitions in the program (one per translation unit).
eg.
class Test
{
static const std::string FILE_NAME;
};
(in some way) is equivalent to:
namespace Test
{
extern const std::string FILE_NAME;
}
, FILE_NAME . .
namespace Test
{
const std::string FILE_NAME;
}
, , .
namespace Test
{
const std::string FILE_NAME = "myfile.txt";
}
Test::FILE_NAME, .