加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 命名空间内的本地函数声明

发布时间:2020-12-16 07:51:55 所属栏目:百科 来源:网络整理
导读:在这种情况下 namespace n { void f() { void another_function(); }} 应该在命名空间n或外部定义函数another_function吗? VS 2012(与November CTP一起)说它应该在外面,Mac上的GCC 4.7.2说应该在里面.如果我做错了,我会从链接器中得到未定义的符号错误. 我
在这种情况下
namespace n {
    void f() {
        void another_function();
    }
}

应该在命名空间n或外部定义函数another_function吗? VS 2012(与November CTP一起)说它应该在外面,Mac上的GCC 4.7.2说应该在里面.如果我做错了,我会从链接器中得到未定义的符号错误.

我一般都相信GCC更符合标准,但这是C,你永远不能确定.

解决方法

C 11 3.5(以及C 03)

7 When a block scope declaration of an entity with linkage is not found
to refer to some other declaration,then that entity is a member of
the innermost enclosing namespace. However such a declaration does not
introduce the member name in its namespace scope.

示例中的声明声明了n :: another_function.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读