Only this one file will use those constant variables.
If I understood correctly, that sentence automatically excludes the first option:
declare static const in the header, define in the source file
You don't need to expose the declaration in other compilation units (cpp files), so you don't need a header file includable in different cpp files.
At this point the following options:
define const in source file in the namespace scope
define static const in source file in the namespace scope
In your situation, the correct answer should be (3).
Why?
The answer is simply the correlation with the meaning of static
variable outside function block.
From here:
The static specifier [...]. When used in a declaration at namespace scope, it specifies internal linkage.
So when you need to declare a constant variable which will be used only in that single compilation unit (cpp file), you should declare it as static const
in order to express the internal linkage more explicit in the reading.
Extra
In general is a good point to use, instead, an anonymous namespace in your compilation unit.
In your .cpp
file:
namespace {
const int kVariable = 12;
}
// no more static const int kVariable = 12;
void foo() {
std::cout << kVariable << '\n';
}
The purpose is practically the same.
Conclusions
All those information give you a general idea about static
keyword in the constant declarations.
Anyway, it is often a matter of style.