如何更改 C++ 引用所引用的变量? [英] How can I change the variable to which a C++ reference refers?

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

问题描述

如果我有这个:

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

如何让ref在这段代码之后引用b?

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

推荐答案

这是不可能的,那就是 按设计.引用不能被反弹.

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

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

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