Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Namespace member definition

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

int main(){}

The above code gives error like so:

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

And

G++ also gives error.

But

VS2010 compiles fine.

My questions are:

a) What is the expected behavior?

b) $7.3.1.2 does not seem to talk about this restriction. Which portion of the Standard guides the behavior of such code?

like image 722
Chubsdad Avatar asked Nov 24 '10 13:11

Chubsdad


1 Answers

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

C++03 Section $8.3 says

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

So your code is ill-formed.

However in discussing issue 548 the CWG agreed that the prohibition of qualified declarators inside their namespace should be lifted1.

1 : Active Issue 482

like image 78
Prasoon Saurav Avatar answered Sep 29 '22 00:09

Prasoon Saurav