gpt4 book ai didi

c++ - C++1z 中的§12.3.2 [class.conv.fct]/1 相对于 C++14 发生了重大变化。是否有意义?

转载 作者:太空狗 更新时间:2023-10-29 20:55:07 26 4
gpt4 key购买 nike

C++14 中的§12.3.2 [class.conv.fct]/1:

A member function of a class X having no parameters with a name of the form

    conversion-function-id:
       operator conversion-type-id
    conversion-type-id:
       type-specifier-seq conversion-declaratoropt
    conversion-declarator:
       ptr-operator conversion-declaratoropt

specifies a conversion from X to the type specified by the conversion-type-id. Such functions are called conversion functions. No return type can be specified. If a conversion function is a member function, the type of the conversion function (8.3.5) is “function taking no parameter returning conversion-type-id”. ...

C++1z 中的§12.3.2 [class.conv.fct]/1:(相关更改在下面突出显示)

A member function of a class X having no parameters with a name of the form

    conversion-function-id:
       operator conversion-type-id
    conversion-type-id:
       type-specifier-seq conversion-declaratoropt
    conversion-declarator:
       ptr-operator conversion-declaratoropt

specifies a conversion from X to the type specified by the conversion-type-id. Such functions are called conversion functions. A decl-specifier in the decl-specifier-seq of a conversion function (if any) shall be neither a defining-type-specifier nor static. Type of the conversion function (8.3.5) is “function taking no parameter returning conversion-type-id”. ...

我想不出没有 decl-specifier-seq 或带有不包含 decl-specifier-seq 的转换函数>定义类型说明符。据我所知,这意味着 conversion-function-id,其 conversion-type-id 没有类型!

最佳答案

conversion-type-id 不包含decl-specifier-seq;它包含一个类型说明符序列

那句话是关于转换函数声明/定义中的这个decl-specifier-seq:

struct C {
constexpr inline explicit operator int() const { return 0; }
// ^^^^^^^^^^^^^^^^^^^^^^^^^
operator float() const;
// ^ no decl-specifier-seq here
};

由于显而易见的原因,它不能包含定义类型说明符

更改的要点在于,当返回类型由 conversion-type-id 确定时,说“无法指定返回类型”会产生误导。

关于c++ - C++1z 中的§12.3.2 [class.conv.fct]/1 相对于 C++14 发生了重大变化。是否有意义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36817129/

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