C ++“命名空间范围” [英] C++ "namespace scope"

查看:124
本文介绍了C ++“命名空间范围”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++规范( http:// www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf ,第7.5.4节)指出


链接规定只能在命名空间范围内发生


命名空间范围到底是什么意思?这是否意味着链接规范,如 externC不能在全局范围内,只能在命名空间中?

这意味着 externC应该只在命名空间范围(不是类范围,块范围等)。不在命名空间,但在全局范围 - 在全局命名空间范围。



bb
$ b由
表示的潜在范围是一个original-namespace-name是由每个
命名空间所建立的声明区域的连接,在与原始命名空间名称相同的声明性区域中的定义。


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?

解决方案

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.

这篇关于C ++“命名空间范围”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆