Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is qualified name in the member function declaration allowed?

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

class X
{
   void X::f();
};
like image 824
Armen Tsirunyan Avatar asked Aug 18 '11 18:08

Armen Tsirunyan


2 Answers

No, this is not valid. Here, X::f is a qualified name; you are attempting to use it as a declarator-id. C++03 8.3[dcl.meaning]/1 lists the circumstances under which a declarator-id may be qualified:

A declarator-id shall not be qualified except for

  • the definition of a member function or static data member outside of its class,

  • the definition or explicit instantiation of a function or variable member of a namespace outside of its namespace, or

  • the definition of a previously declared explicit specialization outside of its namespace, or

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

Because X::f falls into none of these four categories, it is incorrect.

The rule that requires the definition of a member function outside of the class definition to be qualified can be found at C++03 9.3[class.mfct]/5:

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

like image 185
James McNellis Avatar answered Oct 21 '22 04:10

James McNellis


As I understand it is Not valid as per the C++03 Specification.

Reference - C++03 standard:

Section $8.3:

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

I hope I am deriving the appropriate meaning of the above. I will admit reading & understanding the quotes from the Standard makes me a little dizzy. Let me know if I interpret it wrongly.

like image 37
Alok Save Avatar answered Oct 21 '22 03:10

Alok Save