c++ - 当前草案是否允许形成由两个非静态成员声明组成的重载集,其中一个具有引用限定符

标签 c++ overloading language-lawyer c++23

basic.scope#scope-3.3.1

both declare functions with the same parameter-type-list, equivalent ([temp.over.link]) trailing requires-clauses (if any, except as specified in [temp.friend]), and, if both are non-static members, the same cv-qualifiers (if any) and ref-qualifier (if both have one)


上面的规则可以理解为,对于两个具有相同参数类型列表的非静态成员函数,如果有人有一个 cv-qualifiers,那么两个声明应该有相同的 cv-qualifiers;如果两个声明都有 ref-qualifier,则它们应该具有相同的 ref-qualifier。否则,它们不对应。
struct A{
    void show();  //#1
    void show() const &;  //#2
};
在这个片段中,#1 是否对应于 #2?由于 #2 有一个 cv 限定符而 #1 没有,即使具有相同的条件 ref-qualifier是真的,根据规则(注意该规则中强调的 ),它们不对应。那么,这是否意味着草案允许从这两个声明中形成一个重载集?毕竟是over.load#2.3已被 P1787 删除。

最佳答案

此更改是 phrasing the rules more orthogonally 的无意结果,但由于这种正交性允许一些额外的有意义的重载集,所以并不急于“修复”它。特别是,它可能适用于 proposal for deducing this 目前正在考虑中。

关于c++ - 当前草案是否允许形成由两个非静态成员声明组成的重载集,其中一个具有引用限定符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66635738/

相关文章:

java - 编译器的输出与 OCAJP 准备书不同 重载方法

c++ - 是否允许 std::string 的 end+1 迭代器?

c++ - 为什么不调用构造函数?

java - 通过List<>重载java方法

c++ - 使用 boost::numeric::odeint 积分非线性函数 f'(x, y, z) = a + b*I

具有单个参数的java方法重载

c++ - 为什么 shared_ptr 删除器必须是 CopyConstructible 的?

c++ - "Type of bit field too small for number of bits"错误是 C++ 标准的一部分吗?

c++ - opencv代码断言失败错误

C++ 错误 : incomplete type used in nested name specifier