[dcl.fct.default]/3 (重点是我的):
A default argument shall be specified only in the parameter-declaration-clause of a function declaration or lambda-declarator or in a template-parameter (14.1); in the latter case, the initializer-clause shall be an assignment-expression. A default argument shall not be specified for a parameter pack. If it is specified in a parameter-declaration-clause, it shall not occur within a declarator or abstract-declarator of a parameter-declaration.
上面的最后一句表示,如果在参数声明子句中指定了默认参数,则它不会出现在参数声明的声明符或抽象声明符中。然而,当我查看参数声明的定义时,我在 [dcl.fct]/3 中找到以下内容: (重点是我的):
parameter-declaration:
attribute-specifier-seqopt decl-specifier-seq declarator
attribute-specifier-seqopt decl-specifier-seq declarator = initializer-clause
attribute-specifier-seqopt decl-specifier-seq abstract-declaratoropt
attribute-specifier-seqopt decl-specifier-seq abstract-declaratoropt = initializer-clause
最佳答案
标准中有脚注
102) This means that default arguments cannot appear, for example, in declarations of pointers to functions, references to functions, or typedef declarations
例如这些声明
void f(void g(int = 10));
void ( *pf )(int = 10);
错了。
关于c++ - 我不明白 [dcl.fct.default]/3 中的最后一句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44143826/