<分区>
我遇到了以下声明。两个事物驻留在同一地址,即实际变量和引用变量具有相同的内存地址,这怎么可能?
Regardless of how a reference is implemented, a reference has the same memory address as the item it references.
标签 c++
<分区>
我遇到了以下声明。两个事物驻留在同一地址,即实际变量和引用变量具有相同的内存地址,这怎么可能?
Regardless of how a reference is implemented, a reference has the same memory address as the item it references.
最佳答案
那是因为引用不是“事物”:它是对象(可能是变量)的替代名称。
它没有地址:尝试获取引用的地址只会为您提供它别名的对象的地址。
这句话具有误导性。
关于c++ - cpp 中的引用如何具有相同的内存地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46933710/