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?
既可以是,也可以不是。
在这种情况下,不需要存储对象的地址,因此表1就足够了。在另一个示例中,可能需要引用变量的地址。例如当引用是非内联函数的参数时。
please provide a correct representation
C++ 标准草案 N4140 [dcl.ref]/4:
It is unspecified whether or not a reference requires storage
如何可以存储它根本没有指定。
an explanation for why a reference isn't an object.
同一文档定义对象为
[介绍对象]/1
... An object is a region of storage ...
如果一个引用没有被定义为具有存储空间,那么它就没有被定义为一个对象。
关于c++ - 引用变量在内存中是如何表示的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34588945/