here弄清楚
here弄清楚
以下表达式是 xvalue 表达式:
3. a.m,对象表达式的成员,其中a为右值,m为非引用类型的非静态数据成员;
here举个例子
struct X { int n; };
X{4}; // prvalue: does not have an identity
X{4}.n; // xvalue: does have an identity and denotes resources
// that can be reused
但是当我尝试使用
&
至 cout
X{4}.n
的地址,编译器拒绝编译。cout << &X{4}.n << endl; // error C2102: '&' requires l-value
这是否意味着我永远无法获得 xvalue 的地址?
最佳答案
这是标准所说的:[expr.unary.op]/3
The result of the unary
&
operator is a pointer to its operand. The operand shall be an lvalue or a qualified-id.
所以不,你不能使用
&
来获取右值的地址。运算符(operator)。
关于c++ - "xvalue has identity",为什么我不能计算它的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59332607/