decltype和括号 [英] decltype and parentheses

查看:397
本文介绍了decltype和括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I don't understand the last line of the example on page 148 of the FCD (§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&

为什么括号会在这里产生影响?

Why do the parentheses make a difference here? Shouldn't it simply be double like in the line above?

推荐答案

上面的例子,它表示



  • 如果e是未加括号的id表达式或类成员访问(e)是由e指定的实体的类型。

  • 如果e是一个左值,则decltype(e)是T&,其中T是类型of e;

我认为 decltype(a-> x) 是类成员访问的示例, decltype((a-> x))是lvalue的示例。

I think decltype(a->x) is an example of the "class member access" and decltype((a->x)) is an example of lvalue.

这篇关于decltype和括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆