gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:31:34 28 4
gpt4 key购买 nike

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

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com