Does a namespace-scope constructor definition require a class-qualified identifier?

Yes, it says that,

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.

But it doesn't says that member function w/o name shall not be qualified by its class name. Does it? ;)

That seems to lead to an uncertain area depending on implementations. However, the form of A::A is defined by the Standard.

5.1 Primary Expressions

Where class-name :: class-name is used, and the two class-names refer to the same class, this notation names the constructor..

As to whether A(){..} is allowed or not, I guess there is no reason to do it conventionally(Is there ANY C++ compiler allow it?? AFAIK, nope):

  1. Since constructor is a special member function, the way of A::A(){..} is more consistent with other member functions. Why borther allow it to behave specially? That's probably not worth the effort.

  2. No one wants to run the risk of writing non-compliant code that's not explicitly stated in the Standard.


When faced with the tokens S() { } at namespace scope, the compiler can't magically decide it's a ctor. Which grammar rule would produce such a sequence of tokens? Let's ignore everything but function-definitions; they can't produce the ( ){ } part.

That means that S() must be a declarator , and the decl-specifier-seqopt has to be empty (see §8.4.1). §9.2/7 subsequently tells us that the declarator must name a constructor, destructor, or conversion function. But S doesn't name either. Therefore, S() { } is invalid.