为什么无法取得参考地址

为什么无法取得参考地址

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

问题描述



我做了很多尝试并搜索了许多页面,但我仍然想知道为什么我们不能获取参考地址.有人建议它是其他对象的别名,那又如何呢?它必须存储在某个内存位置,不是吗.

有人可以解释吗?

问候

Hi,

I tried a lot and search many pages, but I still wonder why we cannot take address of reference. Some suggest it is alias for some other object, so what? It must be stored at some memory location, isn''t it.

Can anyone explain it?

Regards

推荐答案

int object;
int & refObject = object; // important: there is no way to reassign it to a different object later
int * pRefObject = &refObject;
int * pObject = &object;
// from this point, pRefObject == pObject;

// you can give an name to the object having no name,
// such as dereferenced pointer:

// at this point, the object pObject carries no information on the fact
// that it points to the object named "object" 
// this is how you can named it:
int & namedObject = *pObject; // now it can be used anywhere the name "object" could be used
// (referential transparency, please see the very last link below)



您可能会尝试将引用视为是另一个对象,该对象与被引用对象不同,但这不是引用.这不是另一种指针(但是,例如,.NET引用实质上是尽管通过通过引用"传递参数的语法非常相似;这只是一个不同但相似的概念,用相同的名称表示) ).只是一个提示:所有这些因果关系的东西主要是为了抽象出l值并模拟复杂对象的值语义"而发明的.

请参阅:

http:///publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr110.htm [ ^ ],

http://en.wikipedia.org/wiki/C%2B%2B_reference [ ^ ],
http://www.infernodevelopment.com/simple-c-pointers-and-references [ ^ ],
http://www.parashift.com/c++-faq-lite/references.html [ ^ ],

http://en.wikipedia.org/wiki/Value_%28computer_science%29 [ ^ ].

—SA



You probably try to consider a reference as yes another object, different from the referenced object, but this is not what the reference is. This is not another kind of a pointer (but, for example, .NET reference is, essentially, despite of a great similarity in syntax of passing a parameter "by reference"; this is just a different but similar concept denoted by the same name). Just a hint: all this casuistic stuff is primarily invented to abstract out l-values and simulate "value semantic" for complex objects.

Please see:

http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr110.htm[^],

http://en.wikipedia.org/wiki/C%2B%2B_reference[^],
http://www.infernodevelopment.com/simple-c-pointers-and-references[^],
http://www.parashift.com/c++-faq-lite/references.html[^],

http://en.wikipedia.org/wiki/Value_%28computer_science%29[^].

—SA


这篇关于为什么无法取得参考地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 05:44