From the C++11 standard point of view, is there a technical difference of object status/properties between:
namespace
{
int foo;
const int bar = 42;
}
There is a very big difference: with static
, the name has internal linkage; without it, it has external linkage (but is in a namespace you can't cite in another translation unit). The difference isn't always important, but it does come into play in a few cases: if you have a template with an int*
parameter, for example, you cannot instantiate it on &foo
if foo
is declared static
.
As Steve Jessop has pointed out, this is only true in C++03. C++11 does make a change here. Although I don't know why; I find the C++03 specification more coherent—the namespace something is in shouldn't affect linkage.