Reputation: 5054
Why in the standard c++ grammar, the decl-specifier-seq
under simple-declaration
is optional?
simple-declaration:
decl-specifier-seq(optional) init-declarator-list(optional);
According to the spec, only the constructor, destructor and type conversion functions could have no decl-specifier-seq
(section 9.2 or section 7 dcl.dcl). But all these 3 function declarations are members of a class, so they should be defined by another grammar rule separated from simple-declaration
:
member-declaration:
decl-specifier-seq(optional) member-declarator-list(optional);
function-definition ;(optional)
::(optional) nested-name-specifier template(optional) unqualified-id ;
using-declaration
static_assert-declaration
template-declaration
Here the decl-specifier-seq
is optional as expected. But why in a simple-declaration
, it is optional, too?
Upvotes: 7
Views: 399
Reputation: 331
In C++ you can declare a constructor outside of the class scope.
class A {
A();
};
A::A() {}
Upvotes: 0