gpt4 book ai didi

c++ - decltype 和括号

转载 作者:IT老高 更新时间:2023-10-28 14:01:25 28 4
gpt4 key购买 nike

我不明白 FCD 第 148 页示例的最后一行(第 7.6.1.2/4 节):

const int&& foo();
int i;
struct A { double x; };
const A* a = new A();
decltype(foo()) x1 = i; // type is const int&&
decltype(i) x2; // type is int
decltype(a->x) x3; // type is double
decltype((a->x)) x4 = x3; // type is const double&

为什么括号在这里有所不同?不应该像上一行那样简单地 double 吗?

最佳答案

上面那个例子,它说

  • if e is an unparenthesized id-expression or a class member access (5.2.5), decltype(e) is the type of the entity named by e.
  • if e is an lvalue, decltype(e) is T&, where T is the type of e;

我认为 decltype(a->x) 是“类成员访问”的一个例子,而 decltype((a->x)) 是一个例子左值。

关于c++ - decltype 和括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3097779/

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