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();
};
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With