改变参考 [英] changing reference

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

问题描述




请考虑以下代码...


string a =" 1";

string b =" 2";

string& c = a;


如何更改c以引用b而不是?

解决方案

wi******@gmail.com 写道:


考虑以下代码...


string a =" 1";

string b =" 2" ;;

string& c = a;


如何更改c以引用b而不是?



没有合法的C ++方式。


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问


wi******@gmail.com 写道:
< blockquote class =post_quotes>
考虑以下代码...


string a =" 1";

string b =" ; 2" ;;

string& c = a;


如何更改c以引用b而不是?



没有怎么样:你不能重新安排参考。

最好


Kai-Uwe Bux


7月17日上午8:14,winst ... @ gmail.com写道:





考虑以下代码...


string a =" 1";

string b =" 2";

string& c = a;


如何更改c以引用b而不是?



初始化引用时,它仍然绑定到该对象,因为引用存在时为
。没有办法重新引用

作为另一个对象的引用。


Hi,

consider the following code...

string a = "1";
string b = "2";
string& c = a;

how do I change c to refer to b instead of a?

解决方案

wi******@gmail.com wrote:

consider the following code...

string a = "1";
string b = "2";
string& c = a;

how do I change c to refer to b instead of a?

There is no legal C++ way.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


wi******@gmail.com wrote:

consider the following code...

string a = "1";
string b = "2";
string& c = a;

how do I change c to refer to b instead of a?

There is no "how": you cannot reseat a reference.
Best

Kai-Uwe Bux


On Jul 17, 8:14 am, winst...@gmail.com wrote:

Hi,

consider the following code...

string a = "1";
string b = "2";
string& c = a;

how do I change c to refer to b instead of a?

When a reference is initialized, it remains bound to that object as
long as the reference exists. There is no way to rebind a reference to
a different object.


这篇关于改变参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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