在 C++ 中 standard可以找到纯右值表达式的示例:
"prvalue
The following expressions are prvalue expressions:
a literal (except for string literal), such as 42, true or nullptr;
a function call or an overloaded operator expression of non-reference return type, such as str.substr(1, 2), str1 + str2, or it++; ..."
这是像 T()
(构造函数调用)这样的表达式的位置吗?
这样的表达式有别的名字吗?
最佳答案
虽然默认构造函数的特殊情况让我有点困惑,但这被认为是一个强制转换表达式,在列表中排在后面一点:
- a cast expression to non-reference type, such as
static_cast<double>(x)
,std::string{}
, or(int)42
;
尽管转换nothing 的想法很奇怪,T()
语法确实包含在表格 #4 here 中.
关于c++ - 构造函数调用是纯右值表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44141894/