C ++引用,更改引用的变量 [英] C++ Reference, change the referred variable

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

问题描述

如果我有这个:

int a = 2;
int b = 4;
int &ref = a;

如何让 ref 参考 b 此代码之后?

谢谢!

How can I make ref refer to b after this code?
Thank you!

推荐答案

这是不可能的, =http://stackoverflow.com/questions/728233/why-are-references-not-reseatable-in-c>按设计。参考文献无法反弹。

This is not possible, and that's by design. References cannot be rebound.

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

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