c++ - 我不明白 [dcl.fct.default]/3 中的最后一句

标签 c++ language-lawyer declaration default-arguments

[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/

相关文章:

c++ - 标准库容器和不完整类型的规则是什么?

c++ - 为什么 param_type 构造函数对于随机分布是显式的?

c - 在 C 中多次声明一个函数有什么意义?

c++ - 是否有计算在单色背景上绘制的 Sprite 边界矩形的算法?

c++ - 使用指向文件的指针存储数据结构?

c++ - 如何使用 STL 中的 slist?

c++ - 是 "long long"= "long long int"= "long int long"= "int long long"吗?

c# - 第一个元素作为快速排序中的枢轴

c++ - noexcept 运算符和 enable_if_t : do they work together?

java - 为什么这个缓冲区以下面的方式初始化?