有没有办法找到引用的地址?

2022-01-05 00:00:00 reference c++

有没有办法找到引用的地址?

Is there any way to find the address of a reference?

使其更具体:变量本身的地址,而不是初始化它的变量的地址.

Making it more specific: The address of the variable itself and not the address of the variable it is initialized with.

推荐答案

参考文献没有自己的地址.虽然引用可以实现为指针,但没有必要或保证这一点.

References don't have their own addresses. Although references may be implemented as pointers, there is no need or guarantee of this.

C++ FAQ 说得最好:

与指针不同,一旦引用被绑定到一个对象,它不能重置"到另一个对象.这引用本身不是一个对象(它没有身份;取地址一个参考给你的地址指称者;记住:参考是它的参照物).

Unlike a pointer, once a reference is bound to an object, it can not be "reseated" to another object. The reference itself isn't an object (it has no identity; taking the address of a reference gives you the address of the referent; remember: the reference is its referent).

另请在此处查看我的回答以获取综合列表引用与指针有何不同.

Please also see my answer here for a comprehensive list of how references differ from pointers.

引用是其所指

相关文章