Namespace member definition

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

The above code gives this error:

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

and

g ++ also gives an error.

But

VS2010 compiles fine.

My questions:

a) What is the expected behavior?

b) $ 7.3.1.2 does not seem to indicate this limitation. What part of the Standard defines the behavior of such code?

+6
c ++ definition namespaces member
source share
2 answers

What part of the Standard defines the behavior of such code?

C ++ 03 Section $ 8.3 says

The declaration identifier shall not be qualified other than defining a member function (9.3) or a member of static data (9.4) outside its class, defining or explicitly creating a function or member of a namespace variable outside its namespace, or defining a previously declared explicit specialization outside its space the name or declaration of a friend function that is a member of another class or namespace (11.4).

So your code is poorly formed.

However, in discussing issue 548 , the CWG agreed that the ban on qualified declarators within their namespace should be lifted 1 .

1: Active Release 482

+5
source share

7.3.1.2-2 speaks specifically about this:

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 is considered outside the namespace definition.

0
source share

All Articles