How can I change the variable to which a C++ reference refers?(如何更改 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++ 引用所引用的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!