C++ “namespace scope”

2019-03-02 06:11发布

The C++ spec (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf, section 7.5.4) states that

A linkage-specification shall occur only in namespace scope

What exactly does "namespace scope" mean? Does this mean that a linkage-specification, such as extern "C" can't be in global scope, only in a namespace?
What exactly does "namespace scope" mean?

1条回答
干净又极端
2楼-- · 2019-03-02 06:54

It means, that extern "C" should be only in namespace-scope (not class-scope, block-scope etc.) Something, that is not in namespace, but is in global scope - is in global namespace scope.

The potential scope denoted by an original-namespace-name is the concatenation of the declarative regions established by each of the namespace-definitions in the same declarative region with that original-namespace-name.

查看更多
登录 后发表回答