为什么没有地址有地址? [英] Why don't rvalues have an address?

查看:104
本文介绍了为什么没有地址有地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么rvalue没有内存地址?

Why don't rvalues have a memory address? Are they not loaded into the RAM when the program executes or does it refer to the values stored in processor registers?

推荐答案

您的问题是否正确? (为什么rvalues有内存地址?)有点困惑。右值是一种表达式。 没有地址: 为什么不能将运算符的地址应用到右值表达式?

Your question ("Why don't rvalues have a memory address?") is a bit confused. An rvalue is a kind of expression. Expressions don't have addresses: objects have addresses. It would be more correct to ask "why can one not apply the address-of operator to an rvalue expression?"

这个问题的答案很简单:你只能取一个对象的地址,并不是所有的右值表达式都引用对象(例如,表达式 42 有一个值,而不是一个对象)。

The answer to that is rather simple: you can only take the address of an object and not all rvalue expressions refer to objects (for example, the expression 42 has a value but does not refer to an object).

一些右值表达式引用对象,但这样的对象缺少持久性。由右值表达式引用的对象是一个临时对象,并在创建它的表达式的末尾被销毁。这样的对象确实有地址(你可以通过调用一个临时对象的成员函数来轻松发现这个对象; this 指针必须指向临时对象,因此临时对象必须有一个地址)。

Some rvalue expressions do refer to objects, but such objects lack persistence. An object referred to by an rvalue expression is a temporary object and is destroyed at the end of the expression in which it is created. Such objects do indeed have addresses (you can easily discover this by calling a member function on a temporary object; the this pointer must point to the temporary object and thus the temporary object must have an address).

这是lvalue表达式和rvalue表达式的根本区别。 Lvalue表达式指具有持久性的对象:左值表达式引用的对象超出单个表达式

This is the fundamental difference between lvalue expressions and rvalue expressions. Lvalue expressions refer to objects that have persistence: the object to which an lvalue expression refers persists beyond a single expression.

这篇关于为什么没有地址有地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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