c++ - decltype((x)) 带双括号是什么意思?
问题描述
非常简单的问题,我无法用谷歌搜索答案。
例如:
int a = 0;
int& b = x;
int&& c = 1;
decltype((a)) x; // what is the type of x?
decltype((b)) y; // what is the type of y?
decltype((c)) z; // what is the type of z?
也许我应该将 x、y 和 z 分配给某个值以获得不同的结果,我不确定。
编辑:
根据以下双括号将示例int
转换为参考的站点:
https ://github.com/AnthonyCalandra/modern-cpp-features#decltype
int a = 1; // `a` is declared as type `int`
int&& f = 1; // `f` is declared as type `int&&`
decltype(f) g = 1; // `decltype(f) is `int&&`
decltype((a)) h = g; // `decltype((a))` is int&
解决方案
它们都是 type int&
。
添加括号 like(a)
使它们成为表达式(而不是entity),它们都是左值(作为命名变量);然后decltype
屈服于T&
,即int&
这里。
...
4) 如果参数是任何其他类型的表达式
T
,并且...
b) 如果表达式的值类别是左值,则 decltype 产生
T&
;...
您可以使用此LIVE DEMO(来自编译错误消息)检查实际类型。
推荐阅读
- angular - IONIC 4 - Angular / Firestore
- c# - C#拆分多维数组
- bash - 比较文件和替换 shell 脚本中的数据
- git - 如何通过提交消息和剪切文本从 git 存储库中找出最后一次提交?
- sql - 创建计算列时如何使用条件引用其他列?
- google-cloud-platform - 多区域 Cloud SQL 联合 BigQuery 查询不起作用
- asp.net-core - 为什么 IConfiguration 部分混合了可枚举的值?
- css - 为 Angular CDK 虚拟滚动视口设置动态高度
- ssh - 如何将项目保存到您通过 SSH 连接的文件系统?
- automation - 如何使用赛普拉斯断言下载文件中的值