gpt4 book ai didi

c++ - 命名空间成员定义

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:36:02 31 4
gpt4 key购买 nike

namespace M{
void f();
void M::f(){}
}

int main(){}

上面的代码报错如下:

"ComeauTest.c", line 3: error: qualified name is not allowed in namespace member declaration void M::f(){}

G++ also gives error.

但是

VS2010 compiles fine.

我的问题是:

a) 预期的行为是什么?

b)$7.3.1.2好像没有讲这个限制。标准的哪一部分指导此类代码的行为?

最佳答案

Which portion of the Standard guides the behavior of such code?

C++03 第 $​​8.3 节说

A declarator-id shall not be qualified except for the definition of a member function (9.3) or static data member (9.4) out-side of its class, the definition or explicit instantiation of a function or variable member of a namespace out-side of its namespace, or the definition of a previously declared explicit specialization outside of its name-space, or the declaration of a friend function that is a member of another class or namespace (11.4).

所以你的代码格式不正确。

然而在讨论issue 548 CWG 同意取消在其 namespace 内使用合格声明符的禁令1

1:活跃问题 482

关于c++ - 命名空间成员定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4267423/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com