decltype((x)) 用双括号是什么意思
decltype((x)) with double brackets what does it mean?
非常简单的问题,我无法用谷歌搜索答案。
例如:
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&
它们都属于 int&
类型。
添加像(a)
这样的括号使它们成为表达式(而不是实体(,它们都是左值(作为命名变量(;然后decltype
屈服于T&
,即 int&
这里。
。
4(如果参数是类型为
T
的任何其他表达式,并且。
b( 如果表达式的值类别是左值,则 decltype 产生
T&
;。
您可以使用此实时演示(从编译错误消息中(检查实际类型。
根据C++ Primer
:当我们
decltype
应用于没有任何括号的变量时,我们得到 该变量的类型。如果我们把变量的名字包装在一个或 更多组括号,编译器会将操作数计算为 表达。变量是可以是左侧的表达式 的作业。因此,对此类表达式的decltype
会产生 参考资料:// decltype of a parenthesized variable is always a reference decltype((i)) d; // error: d is int& and must be initialized decltype(i) e; // ok: e is an (uninitialized) int
请注意,如果对象的名称用括号括起来,则将其视为 一个普通的左值表达式,因此 decltype(x( 和 decltype((x(( 是 通常不同类型的。
https://en.cppreference.com/w/cpp/language/decltype
据我了解,(x)
是一个空表达式,它返回对x
的引用。因此
-
decltype(x)
int
-
declytpe((x))
int&
相关文章:
- 这个语法std::class<>{}(arg1, arg2) 在C++中是什么意思?
- 标准 N3337 5.2.10 第 7 条中的C++"类型"是什么意思?
- "类模板示例<int>;"语句对 C++11 是什么意思?
- 线应该是什么意思
- "CID"在AT+HTTPPARA= "CID" ,1中是什么意思
- 表达式"b=(b-x)&x"是什么意思?
- 这个表达是什么意思?
- 此代码验证公式是什么意思?
- 跟踪日志中的T.11803()是什么意思?
- 这个额外的关键字在这个 c++ 类声明中是什么意思?
- * 和 ** 在 C++ 函数声明中是什么意思?
- _T("xyz")是什么意思?
- #define Dbg(fmt,..) (0) 是什么意思? 警告:表达式无效
- 这行代码到底是什么意思?
- 在命名空间名称之前加上 :: 是什么意思?
- 从字符数组的元素中减去'a'是什么意思
- "friend"关键字在C++中是什么意思?
- 减法中的"0"是什么意思?
- 字符数组前面的加号是什么意思?
- 这里的字符串函数是什么意思