My question is very similar with What does "internal linkage" mean?. But I still feel confused so I have to ask.
C++11 ISO says:
A name having namespace scope has internal linkage if it is the name of a variable, function or function template that is explicitly declared static; or ...
When a name has internal linkage, the entity it denotes can be referred to by names from other scopes in the same translation unit.
However, in the following code:
namespace N {
static int t = 3;
}
int main() {
int p = t + 1; // complain here: t is undefined
return 0;
}
Why is it like that? I mean main function and declaration of namespace N are in the same source file so they are in the same translation unit, right? And t has namespace scope and explicitly declared static. So why t is still not found?