引用变量如何在内存中表示? [英] How is a reference variable represented in memory?

查看:64
本文介绍了引用变量如何在内存中表示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int num = 0;
int *ptrNum = #
int &refNum = num;

在存储表1或表2中,引用变量的正确表示是哪一个?
如果是表2,那么为什么指针是对象而引用不是?
如果两种表示都不正确,请提供正确的表示,并解释为什么引用不是对象.

Which one is the correct representation of reference variable in the memory-table 1 or table 2?
If table 2,then why a pointer is an object and a reference isn't?
If both representations are incorrect then please provide a correct representation and an explanation for why a reference isn't an object.

推荐答案

在存储表1或表2中,引用变量的正确表示是哪一个?

Which one is the correct representation of reference variable in the memory-table 1 or table 2?

可以是,也可以不是.

在这种情况下,不需要存储对象的地址,因此表1就足够了.在另一个示例中,可能需要引用变量的地址.例如,当引用是非内联函数的参数时.

In this case, there is no need for storing the address of the object, so the table 1 would be enough. In another example, an address of the referenced variable could be needed. Such as when the reference is an argument of a non-inlined function.

请提供正确的表示形式

please provide a correct representation

C ++标准[dcl.ref]/4的草稿N4140:

draft N4140 of the C++ standard [dcl.ref]/4:

尚不确定引用是否需要存储

It is unspecified whether or not a reference requires storage

完全没有指定

如何进行存储.

How it could be stored is not specified at all.

为什么引用不是对象的说明.

an explanation for why a reference isn't an object.

同一文档将对象定义为

[对象简介]/1

...对象是存储区域...

... An object is a region of storage ...

如果未将引用定义为具有存储,则该引用也未定义为对象.

If a reference is not defined to have storage, then it's not defined to be an object.

这篇关于引用变量如何在内存中表示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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