指向引用的指针 [英] a pointer to a reference

查看:125
本文介绍了指向引用的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++允许引用指针,但是不允许指向

引用,为什么?

C++ allows a reference to a pointer, but doesn''t allow a pointer to a
reference, why?

推荐答案



asdf写道:

asdf wrote:

C ++允许引用指针,但不允许指向

参考,为什么?
C++ allows a reference to a pointer, but doesn''t allow a pointer to a
reference, why?



它的目的是什么?

What would be its purpose?


asdf写道:

asdf wrote:


C ++允许引用指针,但是不允许指向

引用,为什么?
C++ allows a reference to a pointer, but doesn''t allow a pointer to a
reference, why?



你错了:


int main()

{

int i;

int& ref_i = i; //引用int

int * p =& i; //指向int的指针

int * p_ref =& ref_i; //指向int的引用的指针。

}


p_ref是指向引用的指针。现在引用只是另一个变量的别名

,所以p_ref == p,但这仍然与你的

前提相矛盾。


祝你好运,


Tom

You''re mistaken:

int main()
{
int i;
int& ref_i = i; // reference to an int
int* p = &i; // pointer to an int
int* p_ref = &ref_i; // pointer to a reference to an int.
}

p_ref is a pointer to a reference. Now a reference is simply an alias
for another variable, so p_ref==p, but that still contradicts your
premise.

Best regards,

Tom


Thomas Tutone< Th ******** ***@yahoo.comwrote:
Thomas Tutone <Th***********@yahoo.comwrote:

asdf写道:
asdf wrote:

> C ++允许引用一个指针,但不允许指向
引用,为什么?
>C++ allows a reference to a pointer, but doesn''t allow a pointer to a
reference, why?



你错了:


int main()

{

int i;

int& ref_i = i; //引用int

int * p =& i; //指向int的指针

int * p_ref =& ref_i; //指向int的引用的指针。

}


p_ref是指向引用的指针。


You''re mistaken:

int main()
{
int i;
int& ref_i = i; // reference to an int
int* p = &i; // pointer to an int
int* p_ref = &ref_i; // pointer to a reference to an int.
}

p_ref is a pointer to a reference.



我倾向于不同意。一旦参考坐下,任何使用它

实际上是指引用的对象,所以(p_ref =& ref_i)真的意味着

(p_ref =& i ),所以它是一个指向引用对象的指针,但不是

实际上是指向实际引用的指针。虽然,这可能会分裂

头发,我可以看到你的解释也可以看作是正确的,

因为参考文献本身并不存在。

I tend to disagree. Once a reference has been seated, any use of it
really refers to the referenced object, so (p_ref = &ref_i) really means
(p_ref = &i), so it is a pointer to the referenced object, but not
really a pointer to the actual reference. Though, this may be splitting
hairs, and I can see how your interpretation can be seen as correct too,
since a reference doesn''t really exist on its own.


现在引用只是别名

另一个变量,所以p_ref == p,
Now a reference is simply an alias
for another variable, so p_ref==p,



我同意。

This I agree with.


但这仍然与你的
前提相矛盾。
but that still contradicts your
premise.



-

Marcus Kwok

将''invalid''替换为''net''来回复

--
Marcus Kwok
Replace ''invalid'' with ''net'' to reply


这篇关于指向引用的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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