gpt4 book ai didi

c++ - 为什么不编译尾随返回类型中的此运算符用法?

转载 作者:IT老高 更新时间:2023-10-28 22:05:24 24 4
gpt4 key购买 nike

我试图在另一个函数的尾随返回类型中重用运算符的返回类型,但不幸的是,clang 不接受它

struct A {
int operator[](int);
auto at(int i) -> decltype((*this)[i]);
};

Clang 说我的类(class)没有 operator[]。 Gcc 确实接受了我的代码。我的代码真的无效吗?

最佳答案

由于 13.3.1.2p3(第一个项目符号),我会说 clang 是正确的。

For a unary operator @ with an operand of a type whose cv-unqualified version is T1, and for a binary operator @ with a left operand of a type whose cv-unqualified version is T1 and a right operand of a type whose cv-unqualified version is T2, three sets of candidate functions, designated member candidates, nonmember candidates and built-in candidates, are constructed as follows:

  • If T1 is a complete class type, the set of member candidates is the result of the qualified lookup of T1::operator@ (13.3.1.1.1); otherwise, the set of member candidates is empty.

(强调由@sehe添加)

关于c++ - 为什么不编译尾随返回类型中的此运算符用法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14435619/

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