2010-11-24 24 views
6
namespace M{ 
    void f(); 
    void M::f(){} 
} 

int main(){} 

El código anterior da error de este modo:Espacio de nombres definición del miembro

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

Y

G++ also gives error.

Pero

VS2010 compiles fine.

Mis preguntas son:

a) ¿Cuál es el comportamiento esperado?

b) $ 7.3.1.2 no parece hablar de esta restricción. ¿Qué parte del estándar guía el comportamiento de dicho código?

+0

Mira mi respuesta. :) –

Respuesta

5

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

C++ 03 Sección $ 8.3 dice

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

Así se formaron los malos-código.

Sin embargo, en el debate issue 548 el CWG acordó que la prohibición de los declaradores calificados dentro de su espacio de nombres debería ser levantada .

1: Emisión activa 482

0

7.3.1.2-2 habla específicamente sobre este:

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 se considera una definición fuera del espacio de nombres.

Cuestiones relacionadas