如何更改 C++ 引用所引用的变量?

2022-01-05 00:00:00 reference c++ dynamic-rebinding

如果我有这个:

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.

相关文章