Is qualified name allowed in member function declaration?

This code is accepted by MSVC9.0. My question is whether it is legal according to the standard (old and / or new). A quote would be very welcome.

class X { void X::f(); }; 
+6
source share
2 answers

No, this is not true. Here X::f is the qualified name; You are trying to use it as an ad id. C ++ 03 8.3 [dcl.meaning] / 1 lists the circumstances in which an ad identifier can be qualified:

Ad ID must not be qualified except

  • defining a member function or static data element outside its class,

  • defining or explicitly instantiating a function or member of a namespace variable outside its namespace or

  • defining a previously declared explicit specialization outside the namespace or

  • Declaring a friend function that is a member of another class or namespace.

Since X::f does not fall into any of these four categories, this is not true.

A rule requiring a member function definition outside the class definition can be found in C ++ 03 9.3 [class.mfct] / 5:

If the definition of a member function is lexically outside the definition of its class, the name of the member function must be qualified by its class name using the :: operator.

+8
source

As I understand it, this is Not valid according to the C ++ 03 specification.

Link - C ++ 03 standard:

Section $ 8.3:

Each declarator contains exactly one declaration identifier; he calls the declared identifier. The declarator id should be a simple identifier, with the exception of the declaration of some special functions (12.3, 12.4, 13.5) and for the declaration of specialized templates or partial specializations (14.7). The declaration identifier should not be qualified, except for the definition of a member function (9.3) or a static data member (9.4) or a nested class (9.7) outside its class, a definition or explicit instantiation of a function, variable or member of a namespace class outside its namespace or definition a previously declared explicit specialization outside its namespace or the declaration of a friend function that is a member of another class or namespace (11.4).

I hope that I get the appropriate meaning of the above. I admit that reading and understanding quotes from the Standard makes me a little dizzy. Let me know if I misinterpret this.

+7
source

Source: https://habr.com/ru/post/895351/


All Articles