2010-11-24 23 views
6
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では、この制限については言及していません。標準のどの部分がそのようなコードの振る舞いを導くのか?

+0

私の答えをチェックしてください。 :) –

答えて

5

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).

だからあなたのコードが悪い形成されていると言います。

しかし、CWGは、issue 548を議論する際に、名前空間内の修飾宣言子の禁止を解除することに同意しました。

1:アクティブ発行482

0

7.3.1.2-2特にこのことについて協議:

Members of a named namespace can also be defined outside that namespace by explicit qualification (3.4.3.2) of the name being defined, provided that the entity being defined was already declared in the namespace and the definition appears after the point of declaration in a namespace that encloses the declaration’s namespace.

M::fは名前空間定義の外側と考えられています。

関連する問題